using common;
using function;

//using DotNetSpeech;
using game;
using graphics;
using net;

//using Microsoft.Web.WebView2.WinForms;

//*********************************************************
//11 12文件夹 13 文件
//*********************************************************
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Net;
using System.ServiceModel.Syndication;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

//using System.Windows.Documents;
using System.Windows.Forms;

//using System.Windows.Forms.DataVisualization.Charting;
using System.Xml;
using System.Xml.Linq;
using Newtonsoft.Json;
using Diga.WebView2.WinForms;
using Microsoft.Web.WebView2.WinForms;
using System.Threading.Tasks;

public partial class FormMain : FormBase
{
    #region 注释

    //public string strGreen = "..\\@green";

    //List<TabPage> ltp = new List<TabPage>();
    ////int pre = 0;
    ////int next = 0;
    //int cur = 0;

    //List<history> ltp = new List<history>();

    #endregion 注释

    #region 共用变量

    //文件数
    private int iFiles = 0;

    private int iDirectories = 0;
    private int sum = 0;
    private int sum1 = 0;
    private string strSearch = "";
    private string text = "";
    private history curhistory = null;
    private history headhistory = null;
    private history tailhistory = null;

    //List<history>
    public string strDirectName
    {
        get { return text; }
        set { text = value; }
    }

    public string strGreen = "..\\green";
    #endregion 共用变量

    /// <summary>
    /// 构造
    /// </summary>
    public FormMain()
    {
        InitializeComponent();

        //InitializeFlowLayoutPanel();

        FormMain.CheckForIllegalCrossThreadCalls = false;
        this.WindowState = FormWindowState.Maximized;
        StartPosition = FormStartPosition.CenterScreen;
        //arrayListTag = new ArrayList();

        //this.AllowDrop = true;

        //this.Text = coding.bll.xml_help.get_AppName();
        //strGreen = coding.bll.xml_help.get_greensoft();
    }

    private struct ComboBoxItem
    {
        public ComboBoxItem(string a, string b)
        {
            strText = a;
            strValue = b;
        }

        public string strText;
        public string strValue;

        public string Text
        {
            get
            {
                return strText;
            }
            set
            {
                strText = value;
            }
        }

        public string Value
        {
            get
            {
                return strValue;
            }
            set
            {
                strValue = value;
            }
        }
    }

    /// <summary>
    /// 如果windows本机有多个ip，0=局域网IP，1=广域网IP
    /// </summary>
    /// <param name="index"></param>
    /// <returns></returns>
    public static System.Net.IPAddress GetWindowFromIP(int index)
    {
        string hostname;
        System.Net.IPHostEntry localhost;
        System.Net.IPAddress localaddr;

        hostname = System.Net.Dns.GetHostName();
        localhost = System.Net.Dns.GetHostByName(hostname);
        localaddr = localhost.AddressList[index]; //localaddr中就是本机ip地址
        return localaddr;
    }

    public void initRootNode()
    {
        //*********************************************************
        //~~初始化节点
        //*********************************************************
        this.mytreeView.Nodes.Clear();

        //初始化
        //XmlNodeList nodeList = initGetXmlPath();
        XmlDocument doc = new XmlDocument();
        string strPath = "Xml/Path.xml";
        doc.Load(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, strPath));
        XmlNodeList nodeList = doc.SelectSingleNode("data").ChildNodes;

        string strAllPath = "";
        string strDirPath = "";
        string strFlag = "";
        foreach (XmlNode xn in nodeList)
        {
            if (xn.Name == "row")
            {
                //initSetDirectory(ref strAllPath, ref strDirPath, ref strFlag, xn);
                strAllPath = xn["DirectoryRoot"].InnerText;
                strAllPath += xn["Directory"].InnerText;
                if (xn["Directory"].InnerText == "")
                {
                    strDirPath = xn["DirectoryRoot"].InnerText;
                }
                else
                {
                    strDirPath = xn["Directory"].InnerText;
                }
                strFlag = xn["Expand"].InnerText;

                //添加
                if (!System.IO.Directory.Exists(strAllPath)) { continue; }

                TreeNode subNode = initGetDirectoryNode(strAllPath, strDirPath, strFlag);
                this.mytreeView.Nodes.Add(subNode);
            }
        }
    }

    private TreeNode initGetDirectoryNode(string strAllPath, string strDirPath, string strFlag)
    {
        TreeNode subNode = new TreeNode(strDirPath);

        //0 fullpath  1 d or f
        ArrayList arrayListTag = new ArrayList();

        arrayListTag.Add(strAllPath);
        arrayListTag.Add("d");

        subNode.ImageKey = "dir";
        subNode.SelectedImageKey = "dir";
        subNode.Tag = arrayListTag;
        if (strFlag == "1")
        {
            this.mytreeView.BeginUpdate();
            int iDirectories = TreeViewHelper.AddDirectories(subNode);
            int iFiles = TreeViewHelper.AddFiles(subNode);
            this.mytreeView.EndUpdate();

            subNode.Expand();
        }
        return subNode;
    }

    private void init_ImageList()
    {
        //*********************************************************
        //图片list
        //*********************************************************

        #region

        ImageList imageList = new ImageList();

        string strPath = Path.Combine(Environment.CurrentDirectory, "Xml/Img.xml");
        XmlDocument doc = new XmlDocument();
        doc.Load(strPath);

        XmlNodeList nodeList = doc.SelectSingleNode("data").ChildNodes;

        string ImageKey = "";
        string SelectedImageKey = "";
        string ImageKeyPath = "";
        string SelectedImageKeyPath = "";

        foreach (XmlNode xn in nodeList)
        {
            if (xn.Name == "row")
            {
                foreach (XmlNode xn1 in xn.ChildNodes)
                {
                    if (xn1.Name == "ImageKey")
                    {
                        ImageKey = xn1.InnerText.Trim();
                    }
                    else if (xn1.Name == "SelectedImageKey")
                    {
                        SelectedImageKey = xn1.InnerText.Trim();
                    }
                    else if (xn1.Name == "ImageKeyPath")
                    {
                        ImageKeyPath = xn1.InnerText.Trim();
                    }
                    else if (xn1.Name == "SelectedImageKeyPath")
                    {
                        SelectedImageKeyPath = xn1.InnerText.Trim();
                    }
                    else
                    {
                        continue;
                    }
                }
                if (ImageKey == ".java")
                {
                }
                try
                {
                    imageList.Images.Add(ImageKey, new Bitmap(ImageKeyPath.Trim()));
                    imageList.Images.Add(SelectedImageKey, new Bitmap(SelectedImageKeyPath.Trim()));
                }
                catch (Exception ee)
                {
                }
            }
        }
        this.mytreeView.ImageList = imageList;

        #endregion
    }

    private void FormMain_Load(object sender, EventArgs e)
    {
        //this.AutoScaleMode = AutoScaleMode.None;
        this.tabControlCenter.Controls.Clear();
        init_ImageList();
        initRootNode();

        //this.mytreeView.initRootNode();
        //init_combobox_search();
        //*********************************************************
        // 绿色软件
        //*********************************************************
        initOpenSoft();

        LoadButtonConfigs();
    }

    private void initOpenSoft()
    {
        this.常用打开ToolStripMenuItem.DropDownItems.Clear();

        string strPath = "Xml/open.xml";
        XElement xe = XElement.Load(strPath);

        string name = "";
        string rowpath = "";
        foreach (var item in xe.Elements("row"))
        {
            name = item.Element("name").Value;
            rowpath = item.Element("rowpath").Value;

            if (name != "" && rowpath != "")
            {
                if (File.Exists(strGreen + rowpath))
                {
                    ToolStripMenuItem t = new ToolStripMenuItem("打开 " + name);
                    t.Click += new EventHandler(open_Click);
                    t.Tag = strGreen + rowpath;
                    //(t,new UserArgs(strGreen + rowpath)
                    this.常用打开ToolStripMenuItem.DropDownItems.Add(t);
                }
                name = "";
                rowpath = "";
            }
        }

        //string strPath = "Xml/open.xml";
        //XmlDocument doc = new XmlDocument();
        //doc.Load(strPath);
        //XmlNodeList nodeList = doc.SelectSingleNode("data").ChildNodes;

        //string name = "";
        //string rowpath = "";

        //this.常用打开ToolStripMenuItem.DropDownItems.Clear();
        //foreach (XmlNode xn in nodeList)
        //{
        //    if (xn.Name == "row")
        //    {
        //        foreach (XmlNode xn1 in xn.ChildNodes)
        //        {
        //            if (xn1.Name == "name")
        //            {
        //                name = xn1.InnerText;
        //            }
        //            else if (xn1.Name == "rowpath")
        //            {
        //                rowpath = xn1.InnerText;
        //            }
        //        }

        //        if (name != "" && rowpath != "")
        //        {
        //            if (File.Exists(strGreen + rowpath))
        //            {
        //                ToolStripMenuItem t = new ToolStripMenuItem("打开 " + name);
        //                t.Click += new EventHandler(open_Click);
        //                t.Tag = strGreen + rowpath;
        //                //(t,new UserArgs(strGreen + rowpath)
        //                this.常用打开ToolStripMenuItem.DropDownItems.Add(t);
        //            }
        //            name = "";
        //            rowpath = "";
        //        }
        //    }
        //}
    }

    private void open_Click(object sender, EventArgs e)
    {
        string s = (sender as ToolStripMenuItem).Tag.ToString();
        openFile(s);
    }

    #region 搜索

    /// <summary>
    /// 搜索
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void buttonSearch_Click(object sender, EventArgs e)
    {
        search();

        this.textBoxSearch.Focus();
    }

    /// <summary>
    /// 标志是否搜索过
    /// </summary>
    private int flagSearch = 0;

    /// <summary>
    /// 搜索
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void search()
    {
        string word = this.textBoxSearch.Text;

        try
        {
            ///搜索关键词加入数据库
            //search_add(word);
            string str_search = "";
            if (radioButton1.Checked) { str_search = "baidu"; }
            if (radioButton2.Checked) { str_search = "本地"; }
            if (radioButton3.Checked) { str_search = "文字"; }
            //if (radioButton6.Checked) { str_search = "toutiao"; }
            //if (radioButton7.Checked) { str_search = "google"; }

            if (str_search == "本地")
            {
                find();
            }
            else if (str_search == "文字")
            {
                var tb = this.tabControlCenter.SelectedTab;
                if (tb.Controls.Count > 0)
                {
                    if ((tb.Tag as common.TabPageTag).type == "textbox")
                    {
                        this.labelTishi.Text = (tb.Controls[0] as MyRichTextBox).searchString(word, Color.Red).ToString();
                    }
                }
            }
            else if (str_search == "toutiao")
            {
                string url = @"https://search.bilibili.com/all?keyword=" + word + "&from_source=webtop_search&spm_id_from=333.1007";
                //word = System.Web.HttpUtility.UrlEncode(word, System.Text.Encoding.GetEncoding("utf-8")).ToUpper();
                create_tabpage_wangye("toutiao", url);
            }
            else if (str_search == "google")
            {
                //string url = @"https://www.bing.com/search?q=" + word + "";
                string url = "https://www.bing.com/search?q=" + word + "&qs=ds&form=QBRE";
                //word = System.Web.HttpUtility.UrlEncode(word, System.Text.Encoding.GetEncoding("utf-8")).ToUpper();
                create_tabpage_wangye("google", url);
            }
            else if (str_search == "baidu")
            {
                string url = @"http://www.baidu.com/baidu?tn=baidu&&wd=" + word + "";
                //word = System.Web.HttpUtility.UrlEncode(word, System.Text.Encoding.GetEncoding("utf-8")).ToUpper();
                create_tabpage_wangye("baidu", url);

                //string strPath = Path.Combine(Environment.CurrentDirectory, "Xml/search.xml");
                //XElement xe = XElement.Load(strPath);
                //string name = "";
                //string rowpath = "";
                //string defaultkey = "";
                //foreach (var item in xe.Elements("row"))
                //{
                //    if (item.Element("default") != null)
                //    {
                //        defaultkey = item.Element("default").Value;
                //        if (defaultkey == "1")
                //        {
                //            name = item.Element("name").Value;
                //            rowpath = item.Element("rowpath").Value;
                //            string url = string.Format(rowpath, word);
                //            create_tabpage_wangye(name, url);
                //            return;
                //        }
                //    }
                //}
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }

    /// <summary>
    /// 搜索提示添加
    /// </summary>
    /// <param name="word"></param>
    private void search_add(string word)
    {
        //try
        //{
        //    comboBoxSearch.DroppedDown = false;
        //    SqliteHelper.strConnString = "data source=test.db";

        //    string s = "select word from search where word='" + word + "'";
        //    if (SqliteHelper.ExecuteAlone(s) != null) { return; }

        //    StringBuilder sb = new StringBuilder();
        //    //sb.Append("create table if not exists search(word);");
        //    sb.Append("insert into search values('" + word + "');");
        //    string sql = sb.ToString();

        //    SqliteHelper.ExecuteNonQuery(sql);
        //}
        //catch (Exception ee) { }
    }

    /// <summary>
    /// 搜索后展开
    /// </summary>
    /// <param name="treeNodeOne"></param>
    private void expandNode(TreeNode treeNodeOne)
    {
        if (treeNodeOne != this.mytreeView.SelectedNode)
        {
            treeNodeOne.Parent.Expand();
            expandNode(treeNodeOne.Parent);
        }
    }

    /// <summary>
    /// 添加文件夹 文件
    /// </summary>
    /// <param name="tnSubNode"></param>
    private int addDirectoryFileRecuer(TreeNode tnSubNode)
    {
        mytreeView.BeginUpdate();
        tnSubNode.Nodes.Clear();

        int i = 0;

        if (tnSubNode.Tag != null)
        {
            if (TreeViewHelper.GetType(tnSubNode) == "d")
            {
                DirectoryInfo diRoot = new DirectoryInfo(Path.Combine(TreeViewHelper.GetPath(tnSubNode), ""));
                DirectoryInfo[] dirs = diRoot.GetDirectories();

                iDirectories = 0;
                foreach (DirectoryInfo dir in dirs)
                {
                    iDirectories++;
                    TreeNode subNode = new TreeNode(dir.Name);

                    ArrayList arrayListTag = new ArrayList();
                    arrayListTag.Add(dir.FullName);
                    arrayListTag.Add("d");
                    subNode.Tag = arrayListTag;
                    TreeViewHelper.ChangeFileIco(subNode);

                    tnSubNode.Nodes.Add(subNode);

                    i++;

                    i = addDirectoryFileRecuer(subNode);
                }

                FileInfo[] theFiles = diRoot.GetFiles();
                foreach (FileInfo theFile in theFiles)
                {
                    iFiles++;

                    TreeNode subNode = new TreeNode(theFile.Name);

                    ArrayList arrayListTag = new ArrayList();
                    arrayListTag.Add(theFile.FullName);
                    arrayListTag.Add("f");
                    subNode.Tag = arrayListTag;
                    TreeViewHelper.ChangeFileIco(subNode);

                    i++;

                    tnSubNode.Nodes.Add(subNode);
                }
            }
        }

        mytreeView.EndUpdate();

        return i;
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="tn"></param>
    private void refreshColor(TreeNode tn)
    {
        tn.ForeColor = SystemColors.ControlText;
        foreach (TreeNode tnOne in tn.Nodes)
        {
            refreshColor(tnOne);
        }
    }

    /// <summary>
    /// 搜索
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void textBoxSearch_KeyPress(object sender, KeyPressEventArgs e)
    {
        try
        {
            if (e.KeyChar == (char)13)
            {
                find();
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }

    /// <summary>
    ///
    /// </summary>
    private void find()
    {
        if (mytreeView.SelectedNode == null || TreeViewHelper.GetType(mytreeView.SelectedNode) != "d") { return; }

        //sum = TreeViewHelper.GetNodesNumber(treeViewDirect.SelectedNode);

        foreach (TreeNode tn in mytreeView.Nodes)
        {
            refreshColor(tn);
        }

        mytreeView.SelectedNode.ForeColor = Color.Blue;

        //sum = TreeViewHelper.GetNodesNumber(treeViewDirect.SelectedNode);

        System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
        treeViewDirect.CheckForIllegalCrossThreadCalls = false;

        Thread myThread = new Thread(new ThreadStart(find_file_local));
        myThread.Start();

        //Thread myThread = new Thread(new ThreadStart(openProcessBar));
        //myThread.Start();

        //FindFiles();
    }

    /// <summary>
    /// 文件总数
    /// </summary>
    private int fileTotal = 0;

    /// <summary>
    /// 搜索文件
    /// </summary>
    /// <param name="treeNode"></param>
    /// <param name="strSearch"></param>
    private void find_file_file(TreeNode treeNode, string strSearch)
    {
        if (treeNode.Tag != null)
        {
            if (TreeViewHelper.GetType(treeNode) == "d")
            {
                DirectoryInfo diRoot = new DirectoryInfo(Path.Combine(TreeViewHelper.GetPath(treeNode), ""));
                DirectoryInfo[] dirs = diRoot.GetDirectories();

                iDirectories = 0;
                foreach (DirectoryInfo dir in dirs)
                {
                    iDirectories++;
                    TreeNode subNode = new TreeNode(dir.Name);

                    ArrayList arrayListTag = new ArrayList();
                    arrayListTag.Add(dir.FullName);
                    arrayListTag.Add("d");
                    subNode.Tag = arrayListTag;
                    TreeViewHelper.ChangeFileIco(subNode);

                    treeNode.Nodes.Add(subNode);

                    if (subNode.Text.ToUpper().IndexOf(strSearch.ToUpper()) != -1)
                    {
                        subNode.ForeColor = Color.Red;

                        expandNode(subNode);
                    }

                    find_file_file(subNode, strSearch);

                    progressBar1.PerformStep();
                }

                FileInfo[] theFiles = diRoot.GetFiles();
                foreach (FileInfo theFile in theFiles)
                {
                    iFiles++;

                    TreeNode subNode = new TreeNode(theFile.Name);

                    ArrayList arrayListTag = new ArrayList();
                    arrayListTag.Add(theFile.FullName);
                    arrayListTag.Add("f");
                    subNode.Tag = arrayListTag;
                    TreeViewHelper.ChangeFileIco(subNode);

                    treeNode.Nodes.Add(subNode);

                    if (subNode.Text.ToUpper().IndexOf(strSearch.ToUpper()) != -1)
                    {
                        subNode.ForeColor = Color.Red;
                        expandNode(subNode);

                        subNode.EnsureVisible();

                        //if (fileTotal == 0)
                        //{
                        //    selectedNode = subNode;
                        //}

                        fileTotal++;
                    }

                    //sum1++;
                    //int j = 100 * sum1 / sum;
                    //bw.ReportProgress(j);

                    progressBar1.PerformStep();
                }
            }
        }
    }

    //TreeNode selectedNode;

    private void find_file_local()
    {
        try
        {
            fileTotal = 0;

            int sum1 = 0;
            TreeNode treeNode = mytreeView.SelectedNode;
            string strSearch = textBoxSearch.Text;
            DirectoryInfo diRoot = new DirectoryInfo(Path.Combine(TreeViewHelper.GetPath(treeNode), ""));
            sum = FileCtrl.get_file_number(diRoot, ref sum1);

            //this.labelTishi.Text = "file " + sum;
            //sum = TreeViewHelper.GetNodesNumber(treeNode);

            this.progressBar1.Visible = true;
            this.progressBar1.Step = 1;
            this.progressBar1.Value = 1;
            progressBar1.Minimum = 1;
            progressBar1.Maximum = sum;

            treeNode.Nodes.Clear();

            this.Invoke(new find_file_fileDelegate(find_file_file), new object[] { treeNode, strSearch });
            //if (selectedNode != null) {
            //    this.treeViewDirect.SelectedNode = selectedNode;
            //    selectedNode = null;
            //}
            this.labelTishi.Text = "" + fileTotal;
            //this.labelTishi.Text = "file number:" + fileTotal;
        }
        catch (Exception ee)
        {
        }
    }

    private delegate void find_file_fileDelegate(TreeNode treeNode, string strSearch);

    private void openProcessBar()
    {
        FormProcessBar fpb = new FormProcessBar(sum, this);
        //fpb.MdiParent = this;

        DialogResult dia = fpb.ShowDialog();
        //if (dia == DialogResult.OK)
        //{
        //    //MessageBox.Show("ok");

        //}
    }

    private delegate void SetVisibleDelegate(BackgroundWorker bw, DoWorkEventArgs e);

    private void SetVisible(BackgroundWorker bw, DoWorkEventArgs e)
    {
        findFile(mytreeView.SelectedNode, this.textBoxSearch.Text, bw, e);
    }

    //treeview递归
    /// <summary>
    /// 搜索
    /// </summary>
    /// <param name="dir"></param>
    private void findFile(TreeNode treeNode, string strSearch, BackgroundWorker bw, DoWorkEventArgs e)
    {
        treeNode.Nodes.Clear();

        if (treeNode.Tag != null)
        {
            if (TreeViewHelper.GetType(treeNode) == "d")
            {
                DirectoryInfo diRoot = new DirectoryInfo(Path.Combine(TreeViewHelper.GetPath(treeNode), ""));
                DirectoryInfo[] dirs = diRoot.GetDirectories();

                iDirectories = 0;
                foreach (DirectoryInfo dir in dirs)
                {
                    iDirectories++;
                    TreeNode subNode = new TreeNode(dir.Name);

                    ArrayList arrayListTag = new ArrayList();
                    arrayListTag.Add(dir.FullName);
                    arrayListTag.Add("d");
                    subNode.Tag = arrayListTag;
                    TreeViewHelper.ChangeFileIco(subNode);

                    treeNode.Nodes.Add(subNode);

                    if (subNode.Text.ToUpper().IndexOf(strSearch.ToUpper()) != -1)
                    {
                        subNode.ForeColor = Color.Red;
                        expandNode(subNode);
                    }

                    sum1++;
                    int j = 100 * sum1 / sum;
                    bw.ReportProgress(j);

                    findFile(subNode, strSearch, bw, e);
                }

                FileInfo[] theFiles = diRoot.GetFiles();
                foreach (FileInfo theFile in theFiles)
                {
                    iFiles++;

                    TreeNode subNode = new TreeNode(theFile.Name);

                    ArrayList arrayListTag = new ArrayList();
                    arrayListTag.Add(theFile.FullName);
                    arrayListTag.Add("f");
                    subNode.Tag = arrayListTag;
                    TreeViewHelper.ChangeFileIco(subNode);

                    treeNode.Nodes.Add(subNode);

                    if (subNode.Text.ToUpper().IndexOf(strSearch.ToUpper()) != -1)
                    {
                        subNode.ForeColor = Color.Red;
                        expandNode(subNode);
                    }

                    sum1++;
                    int j = 100 * sum1 / sum;
                    bw.ReportProgress(j);
                }
            }
        }
    }

    //private void FindFileDo(BackgroundWorker bw, DoWorkEventArgs e) { }

    public void findFiles(BackgroundWorker bw, DoWorkEventArgs e)
    {
        this.Invoke(new SetVisibleDelegate(SetVisible), new object[] { bw, e });
    }

    #endregion 搜索

    #region 废弃

    protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, Keys keyData)
    {
        //相当于拿到其他进程的key事件

        //if (keyData == Keys.F3)
        //{
        //    if (oldtabpage != null)
        //        this.tabControlCenter.SelectedTab = oldtabpage;
        //    return base.ProcessCmdKey(ref msg, keyData);
        //}

        return base.ProcessCmdKey(ref msg, keyData);
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="bGworker"></param>
    /// <param name="e"></param>
    //public void CreateFindFile(BackgroundWorker bGworker, DoWorkEventArgs e)
    //{
    //    //foreach (TreeNode tn in treeViewDirect.Nodes)
    //    //{
    //    //    RefreshColor(tn);
    //    //}
    //    //bGworker.ReportProgress(20);

    //    //treeViewDirect.SelectedNode.ForeColor = Color.Blue;

    //    //AddAllRecuer(treeViewDirect.SelectedNode);
    //    //bGworker.ReportProgress(60);

    //    //FindFile(treeViewDirect.SelectedNode, this.textBoxSearch.Text);
    //    //bGworker.ReportProgress(100);

    //}
    /// <summary>
    ///
    /// </summary>
    //private csExWB.cEXWB m_CurWB = null; //Current WB

    /// <summary>
    ///
    /// </summary>
    /// <param name="sUrl"></param>
    //private void NavToUrl(string sUrl)
    //{
    //    try
    //    {
    //        m_CurWB.Navigate(sUrl);
    //    }
    //    catch (Exception ee)
    //    {
    //    }
    //}

    #endregion 废弃

    #region 窗体事件

    /// <summary>
    /// 关闭
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void FormMain_FormClosed(object sender, FormClosedEventArgs e)
    {
        //this.Controls.Clear();

        this.Dispose();
        Application.Exit();
    }

    #endregion 窗体事件

    #region TabPage 事件

    /// <summary>
    /// 临时文件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void panelCenter_DoubleClick(object sender, MouseEventArgs e)
    {
        TabPage tp = new TabPage();
        tp.Text = "@@Temp";
        tp.Tag = "null";

        this.tabControlCenter.Controls.Add(tp);
        this.tabControlCenter.SelectedTab = tp;

        //RichTextBoxExtended richTextBoxExtended = new RichTextBoxExtended();
        //SearchableControls.SearchableRichTextBox richTextBoxExtended = new SearchableControls.SearchableRichTextBox();
        MyRichTextBox richTextBoxExtended = new MyRichTextBox();

        richTextBoxExtended.Dock = DockStyle.Fill;

        tp.Controls.Add(richTextBoxExtended);
    }

    private void closeTab(TabPage tb)
    {
        clearresouce(tb);

        //if (tb.Controls.Count > 0)
        //{
        //    if (tb.Controls[0].Tag != null)
        //    {
        //        if (tb.Controls[0].Tag.ToString() == "img")
        //        {
        //            Image bb = ((PictureBox)(tb.Controls[0].Controls[0])).Image;
        //            bb.Dispose();
        //        }
        //        else if (tb.Controls[0].Tag.ToString() == "wangye")
        //        {
        //            ((WebBrowser)(tb.Controls[0].Controls[0])).Dispose();
        //        }
        //    }

        //}

        //foreach (var item in tb.Controls)
        //{
        //    if (item is PictureBox) {
        //        (item as PictureBox).Image.Dispose();
        //    }
        //}

        //GC.Collect();
        tb.Dispose();
        if (this.tabControlCenter.SelectedTab != null)
        {
            //this.tabControlCenter.SelectedTab.Select();
            this.tabControlCenter.Focus();
        }
    }

    //观察者模式清理资源 主要清理朗读中的com资源
    //delegate
    private delegate void aa();

    private event aa ee;

    private void clearresouce(Control cc)
    {
        if (ee != null)
        {
            ee();
            ee = null;
        }

        //throw new NotImplementedException();
        foreach (Control item in cc.Controls)
        {
            clearresouce(item);
        }

        //if (cc is PictureBox)
        //{
        //    (cc as PictureBox).Image.Dispose();
        //}
        //else if (cc is WebBrowser)
        //{
        //    (cc as WebBrowser).Dispose();
        //}
    }

    /// <summary>
    /// 删除一页
    /// </summary>
    private void history_del()
    {
        if (curhistory != null)
        {
            if (curhistory.next != null)
            {
                curhistory.next.pre = curhistory.pre;
            }
            if (curhistory.pre != null)
            {
                curhistory.pre.next = curhistory.next;
            }
            if (curhistory.pre != null && curhistory.pre.node != null)
            {
                //tabControlCenter.SelectedTab = curhistory.pre.node;
                curhistory = curhistory.pre;
            }
        }
    }

    /// <summary>
    /// 关闭本页 双击时候要关闭页 要修改历史记录 cur等于要关闭的页
    /// cur.pre=cur.pre.pre pre=cur cur.delete
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void tabControlCenter_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        tab_del();
    }

    private void tab_del()
    {
        if (tabControlCenter.SelectedTab != null)
        {
            closeTab(tabControlCenter.SelectedTab);
        }
    }

    #endregion TabPage 事件

    #region tree 事件

    private void createDirectory()
    {
        try
        {
            if (((ArrayList)this.mytreeView.SelectedNode.Tag)[1].ToString() == "d")
            {
                string strFileName = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace(":", "");
                string strFile = Path.Combine(((ArrayList)this.mytreeView.SelectedNode.Tag)[0].ToString(), strFileName);
                Directory.CreateDirectory(strFile);
                TreeNode tnNew = new TreeNode(strFileName);

                ArrayList arrayListTag = new ArrayList();
                arrayListTag.Add(strFile);
                arrayListTag.Add("d");
                tnNew.Tag = arrayListTag;

                TreeViewHelper.ChangeFileIco(tnNew);

                mytreeView.SelectedNode.Nodes.Add(tnNew);
                mytreeView.SelectedNode = tnNew;
            }
            else
            {
                string strFile = Path.Combine(((ArrayList)this.mytreeView.SelectedNode.Parent.Tag)[0].ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Replace(":", "");
                Directory.CreateDirectory(strFile);
                TreeNode tnNew = new TreeNode(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace(":", ""));

                ArrayList arrayListTag = new ArrayList();
                arrayListTag.Add(strFile);
                arrayListTag.Add("d");
                tnNew.Tag = arrayListTag;

                TreeViewHelper.ChangeFileIco(tnNew);

                mytreeView.SelectedNode.Parent.Nodes.Add(tnNew);
                mytreeView.SelectedNode = tnNew;
            }
        }
        catch (Exception)
        {
            throw;
        }
    }

    /// <summary>
    /// 增加文件夹
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void toolStripMenuItemAdddirector_Click(object sender, EventArgs e)
    {
        createDirectory();
    }

    /// <summary>
    /// 增加文件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void toolStripMenuItemAddFile_Click(object sender, EventArgs e)
    {
        ToolStripMenuItem_Click_add("txt");

        //try
        //{
        //    if (((ArrayList)this.treeViewDirect.SelectedNode.Tag)[1].ToString() == "d")
        //    {
        //        //string strFileName = (DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ".txt").Replace(":", "");
        //        //string strFile = Path.Combine(((ArrayList)this.treeViewDirect.SelectedNode.Tag)[0].ToString(), strFileName);
        //        //FileStream fs = File.Create(strFile);
        //        ////Thread.Sleep(1000);

        //        //if (fs.Handle == null)
        //        //{
        //        //    Thread.Sleep(2000);
        //        //}
        //        //else
        //        //{
        //        //    fs.Dispose();
        //        //}

        //        string path=((ArrayList)this.treeViewDirect.SelectedNode.Tag)[0].ToString();
        //        add a=add_factory.get_add("txt");
        //        a.create_file(path);

        //        TreeNode tnNew = new TreeNode(a.filename);

        //        ArrayList arrayListTag = new ArrayList();
        //        arrayListTag.Add(a.filepath);
        //        arrayListTag.Add("f");
        //        tnNew.Tag = arrayListTag;

        //        TreeViewHelper.ChangeFileIco(tnNew);

        //        treeViewDirect.SelectedNode.Nodes.Add(tnNew);
        //        treeViewDirect.SelectedNode = tnNew;

        //        LoadText(tnNew);

        //    }
        //    else
        //    {
        //        MessageBox.Show("从文件夹建立文件");
        //        //string strFileName = (DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ".txt").Replace(":", "");
        //        //string strFile = Path.Combine(((ArrayList)this.treeViewDirect.SelectedNode.Parent.Tag)[0].ToString(), strFileName);
        //        //File.Create(strFile.Replace(":", ""));
        //        ////Thread.Sleep(1000);

        //        //TreeNode tnNew = new TreeNode(strFileName);
        //        //ArrayList arrayListTag = new ArrayList();
        //        //arrayListTag.Add(strFile);
        //        //arrayListTag.Add("f");
        //        //tnNew.Tag = arrayListTag;

        //        //TreeViewHelper.ChangeFileIco(tnNew);

        //        //treeViewDirect.SelectedNode.Parent.Nodes.Add(tnNew);
        //        //treeViewDirect.SelectedNode = tnNew;

        //        //LoadText(tnNew);
        //    }

        //}
        //catch (Exception ee)
        //{
        //}
    }

    #region 拖拽

    /// <summary>
    /// 拖动时 检查包含关系 把第一个拖动到第二个
    /// 如果第二个是文件夹 只要证明a的parent==b就可以了
    /// 如果是文件 a.parent=b.parent
    ///
    /// </summary>
    /// <param name="node1"></param>
    /// <param name="node2"></param>
    /// <returns></returns>
    private bool containsNode(TreeNode node1, TreeNode node2)
    {
        if (((ArrayList)(node2.Tag))[1] == "d")
        {
            if (node1.Parent.Equals(node2)) return true;
        }
        else
        {
            if (node1.Parent.Equals(node2.Parent)) return true;
        }
        return false;

        //if (node2.Parent == null) return false;

        /////包含 第一个是文件 第二个文件夹
        //if (node1.Parent.Equals(node2)) return true;

        //return containsNode(node1, node2.Parent);
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="tn"></param>
    /// <param name="temp"></param>
    private void GetAllChildNode(TreeNode tn, ref ArrayList temp)
    {
        if (tn.Nodes.Count != 0)
        {
            foreach (TreeNode tt in tn.Nodes)
            {
                temp.Add(tt);

                if (tt.Nodes.Count != 0)
                {
                    GetAllChildNode(tt, ref temp);
                }
            }
        }
    }

    /// <summary>
    /// 传入arraylist 返回所有文本结点
    /// </summary>
    /// <param name="tn"></param>
    /// <param name="temp"></param>
    private void GetAllChildNodeText(TreeNode tn, ref ArrayList temp)
    {
        if (tn.Nodes.Count != 0)
        {
            foreach (TreeNode tt in tn.Nodes)
            {
                if (TreeViewHelper.GetType(tt) == "f")
                {
                    temp.Add(tt);
                }
                else
                {
                    if (tt.Nodes.Count != 0)
                    {
                        GetAllChildNodeText(tt, ref temp);
                    }
                }
            }
        }
    }

    /// <summary>
    // 拖动结束 拖动实现
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void treeViewDirect_DragDrop(object sender, DragEventArgs e)
    {
        //*********************************************************
        //结点拖动
        //*********************************************************

        #region 结点拖动

        if (e.Data.GetData(DataFormats.FileDrop) == null)
        {
            Point targetPoint = mytreeView.PointToClient(new Point(e.X, e.Y));
            TreeNode targetNode = mytreeView.GetNodeAt(targetPoint);
            TreeNode draggedNode = (TreeNode)e.Data.GetData(typeof(TreeNode));

            string newPath;
            string oldPath;

            //*********************************************************
            //关闭 TabControlPage
            //*********************************************************
            if (((ArrayList)draggedNode.Tag)[1].ToString() == "f")
            {
                TabControlHelp.CloseTabControlPage(this.tabControlCenter, ((ArrayList)draggedNode.Tag)[0].ToString());
            }
            else if (TreeViewHelper.GetType(draggedNode) == "d")
            {
                ArrayList al = new ArrayList();
                GetAllChildNodeText(draggedNode, ref al);
                foreach (object o in al)
                {
                    TabControlHelp.CloseTabControlPage(this.tabControlCenter, ((ArrayList)((TreeNode)(o)).Tag)[0].ToString());
                }
            }
            //*********************************************************
            //关闭 TabControlPage
            //*********************************************************

            if (!draggedNode.Equals(targetNode) && !containsNode(draggedNode, targetNode))
            {
                // If it is a move operation, remove the node from its current
                // location and add it to the node at the drop location.
                if (e.Effect == DragDropEffects.Move)
                {
                    //*********************************************************
                    //目标是文件夹
                    //*********************************************************
                    if (TreeViewHelper.GetType(targetNode) == "d")
                    {
                        if (((ArrayList)draggedNode.Tag)[1].ToString() == "f")
                        {
                            oldPath = ((ArrayList)draggedNode.Tag)[0].ToString();
                            newPath = Path.Combine(((ArrayList)targetNode.Tag)[0].ToString(), draggedNode.Text);

                            ///这里是判断是复制还是移动 ctrl==8 这时候是复制
                            ///
                            if (e.KeyState == 8)
                            {
                                FileInfo f = new FileInfo(oldPath);
                                if (!File.Exists(newPath))
                                {
                                    f.CopyTo(newPath);
                                }
                            }
                            else
                            {
                                File.Move(oldPath, newPath);
                                draggedNode.Remove();
                            }

                            ArrayList arrayListTag = new ArrayList();
                            arrayListTag.Add(newPath);
                            arrayListTag.Add("f");

                            TreeNode draggedNode1 = draggedNode.Clone() as TreeNode;
                            //draggedNode.Tag = arrayListTag;
                            draggedNode1.Tag = arrayListTag;

                            targetNode.Nodes.Add(draggedNode1);
                            targetNode.Expand();
                        }
                        else
                        {
                            oldPath = ((ArrayList)draggedNode.Tag)[0].ToString();
                            newPath = Path.Combine(((ArrayList)targetNode.Tag)[0].ToString(), draggedNode.Text);

                            Directory.Move(oldPath, newPath);

                            draggedNode.Remove();

                            ArrayList arrayListTag = new ArrayList();
                            arrayListTag.Add(newPath);
                            arrayListTag.Add("d");
                            draggedNode.Tag = arrayListTag;

                            if (draggedNode.IsExpanded)
                            {
                                LoadDirAndFile(draggedNode);
                            }

                            targetNode.Nodes.Add(draggedNode);

                            targetNode.Expand();
                        }
                    }

                    //*********************************************************
                    //目标是文件
                    //*********************************************************
                    else
                    {
                        if (TreeViewHelper.GetType(draggedNode) == "f")
                        {
                            oldPath = ((ArrayList)draggedNode.Tag)[0].ToString();
                            newPath = Path.Combine(((ArrayList)targetNode.Parent.Tag)[0].ToString(), draggedNode.Text);

                            //File.Move(oldPath, newPath);

                            //draggedNode.Remove();

                            //ArrayList arrayListTag = new ArrayList();
                            //arrayListTag.Add(newPath);
                            //arrayListTag.Add("f");
                            //draggedNode.Tag = arrayListTag;

                            //targetNode.Parent.Nodes.Add(draggedNode);
                            //targetNode.Parent.Expand();

                            ///这里是判断是复制还是移动 ctrl==8 这时候是复制
                            ///
                            if (e.KeyState == 8)
                            {
                                FileInfo f = new FileInfo(oldPath);
                                if (!File.Exists(newPath))
                                {
                                    f.CopyTo(newPath);
                                }
                            }
                            else
                            {
                                File.Move(oldPath, newPath);
                                draggedNode.Remove();
                            }

                            ArrayList arrayListTag = new ArrayList();
                            arrayListTag.Add(newPath);
                            arrayListTag.Add("f");

                            TreeNode draggedNode1 = draggedNode.Clone() as TreeNode;
                            //draggedNode.Tag = arrayListTag;
                            draggedNode1.Tag = arrayListTag;

                            targetNode.Parent.Nodes.Add(draggedNode1);
                            targetNode.Parent.Expand();
                        }
                        else
                        {
                            oldPath = ((ArrayList)draggedNode.Tag)[0].ToString();
                            newPath = ((ArrayList)targetNode.Parent.Tag)[0].ToString();

                            Directory.Move(oldPath, newPath);

                            ArrayList arrayListTag = new ArrayList();
                            arrayListTag.Add(newPath);
                            arrayListTag.Add("d");
                            draggedNode.Tag = arrayListTag;

                            draggedNode.Remove();

                            if (draggedNode.IsExpanded)
                            {
                                LoadDirAndFile(draggedNode);
                            }

                            targetNode.Parent.Nodes.Add(draggedNode);
                            targetNode.Parent.Expand();
                        }
                    }
                }
            }

            //*********************************************************
            //移动最后工作
            //*********************************************************
            //xuan zhong
            this.mytreeView.SelectedNode = draggedNode;
        }

        #endregion 结点拖动

        //*********************************************************
        //桌面文件拖进来
        //*********************************************************

        #region
        else
        {
            Point targetPoint = mytreeView.PointToClient(new Point(e.X, e.Y));
            TreeNode targetNode = mytreeView.GetNodeAt(targetPoint);

            string newPath;
            string oldPath;

            for (int i = 0; i < ((System.Array)e.Data.GetData(DataFormats.FileDrop)).Length; i++)
            {
                oldPath = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(i).ToString();
                TreeNode draggedNode = new TreeNode();

                //*********************************************************
                //文件夹
                //*********************************************************
                if (TreeViewHelper.GetType(targetNode) == "d")
                {
                    if (Path.GetExtension(oldPath) != "")
                    {
                        string strFile = Path.GetFileName(oldPath);
                        newPath = Path.Combine(((ArrayList)targetNode.Tag)[0].ToString(), strFile);

                        draggedNode.Text = strFile;
                        ArrayList arrayListTag = new ArrayList();
                        arrayListTag.Add(newPath);
                        arrayListTag.Add("f");
                        draggedNode.Tag = arrayListTag;

                        TreeViewHelper.ChangeFileIco(draggedNode);

                        targetNode.Nodes.Add(draggedNode);
                        targetNode.Expand();

                        File.Move(oldPath, newPath);
                    }
                    else
                    {
                        string strFile = Path.GetFileName(oldPath);
                        newPath = Path.Combine(((ArrayList)targetNode.Tag)[0].ToString(), strFile);

                        draggedNode.Text = strFile;
                        ArrayList arrayListTag = new ArrayList();
                        arrayListTag.Add(newPath);
                        arrayListTag.Add("d");
                        draggedNode.Tag = arrayListTag;

                        TreeViewHelper.ChangeFileIco(draggedNode);

                        targetNode.Nodes.Add(draggedNode);
                        targetNode.Expand();

                        try
                        {
                            FileCtrl.FolderCopy(oldPath, newPath, true);
                            FileCtrl.DirectoryDelete(oldPath);
                        }
                        catch (Exception ee)
                        {
                        }
                    }
                }

                //*********************************************************
                //文件
                //*********************************************************
                else
                {
                    if (Path.GetExtension(oldPath) != "")
                    {
                        string strFile = Path.GetFileName(oldPath);
                        newPath = Path.Combine(TreeViewHelper.GetPath(targetNode.Parent), strFile);

                        draggedNode.Text = strFile;
                        ArrayList arrayListTag = new ArrayList();
                        arrayListTag.Add(newPath);
                        arrayListTag.Add("f");
                        draggedNode.Tag = arrayListTag;
                        TreeViewHelper.ChangeFileIco(draggedNode);

                        targetNode.Parent.Nodes.Add(draggedNode);
                        targetNode.Parent.Expand();

                        File.Move(oldPath, newPath);
                    }
                    else
                    {
                        string strFile = Path.GetFileName(oldPath);
                        newPath = Path.Combine(TreeViewHelper.GetPath(targetNode.Parent), strFile);

                        draggedNode.Text = strFile;
                        ArrayList arrayListTag = new ArrayList();
                        arrayListTag.Add(newPath);
                        arrayListTag.Add("d");
                        draggedNode.Tag = arrayListTag;

                        TreeViewHelper.ChangeFileIco(draggedNode);

                        targetNode.Parent.Nodes.Add(draggedNode);
                        targetNode.Parent.Expand();

                        FileCtrl.FolderCopy(oldPath, newPath, true);
                        FileCtrl.DirectoryDelete(oldPath);
                    }
                }

                //xuan zhong
                this.mytreeView.SelectedNode = draggedNode;
            }
        }

        #endregion 拖拽
    }

    /// <summary>
    /// 拖动进行中
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private TreeNode treeNodeCurrent = new TreeNode();

    /// <summary>
    /// wuxiao
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void treeViewDirect_DragOver(object sender, DragEventArgs e)
    {
        //Point targetPoint = treeViewDirect.PointToClient(new Point(e.X, e.Y));
        //this.treeViewDirect.Location.Y

        //treeNodeCurrent = treeViewDirect.GetNodeAt(targetPoint);
        //this.treeViewDirect.SelectedNode = treeNodeCurrent;
    }

    /// <summary>
    /// 拖动之前 固定写法
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void treeViewDirect_ItemDrag(object sender, ItemDragEventArgs e)
    {
        try
        {
            if (e.Button == MouseButtons.Left)
            {
                DoDragDrop(e.Item, DragDropEffects.Move);
            }
        }
        catch (Exception ex) { MessageBox.Show(ex.Message); }
    }

    /// <summary>
    /// 开始 拖动效果
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void treeViewDirect_DragEnter(object sender, DragEventArgs e)
    {
        e.Effect = e.AllowedEffect;
    }

    #endregion tree 事件

    #region Rename

    /// <summary>
    /// Handles the AfterLabelEdit event of the treeViewDirect control.
    /// 改名
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.Windows.Forms.NodeLabelEditEventArgs"/> instance containing the event data.</param>
    /// <remarks>This method will rename the currently selected node if the text has changed.</remarks>
    private void treeViewDirect_AfterLabelEdit(object sender, System.Windows.Forms.NodeLabelEditEventArgs e)
    {
        try
        {
            if (e.Node.Text == e.Label || e.Label == null) { return; }

            if ((!e.CancelEdit) && (string.Compare(e.Label, e.Node.Text, false) != 0))
            {
                if (((ArrayList)e.Node.Tag)[1].ToString() == "d")
                {
                    DirectoryInfo d = new DirectoryInfo(((ArrayList)e.Node.Tag)[0].ToString());
                    string strDir = d.FullName.Substring(0, d.FullName.LastIndexOf("\\") + 1) + e.Label;
                    d.MoveTo(strDir);

                    ArrayList arrayListTag = new ArrayList();
                    arrayListTag.Add(strDir);
                    arrayListTag.Add("d");
                    e.Node.Tag = arrayListTag;

                    this.mytreeView.SelectedNode = e.Node;

                    mytreeView.LabelEdit = false;

                    LoadDirAndFile(e.Node);

                    return;
                }

                if (((ArrayList)e.Node.Tag)[1].ToString() == "f")
                {
                    foreach (TabPage tpTemp in tabControlCenter.Controls)
                    {
                        if (tpTemp.Tag as common.TabPageTag != null && (tpTemp.Tag as common.TabPageTag).filename == ((ArrayList)e.Node.Tag)[0].ToString())
                        {
                            tpTemp.Dispose();
                            e.Node.Text = e.Label;
                        }
                    }

                    string strFile = ((ArrayList)e.Node.Tag)[0].ToString().Substring(0, ((ArrayList)e.Node.Tag)[0].ToString().LastIndexOf("\\") + 1) + e.Label;

                    this.MoveFile(((ArrayList)e.Node.Tag)[0].ToString(), strFile);

                    ArrayList arrayListTag = new ArrayList();
                    arrayListTag.Add(strFile);
                    arrayListTag.Add("f");
                    e.Node.Tag = arrayListTag;

                    LoadText(e.Node);
                    TreeViewHelper.ChangeFileIco(e.Node);

                    mytreeView.LabelEdit = false;
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

    /// <summary>
    /// Renames the specified shortcut in the current folder.
    /// </summary>
    /// <param name="oldUrlName">The name of the shortcut to be renamed.</param>
    /// <param name="newUrlName">The new name of the shortcut.</param>
    public void MoveFile(string oldUrlName, string newUrlName)
    {
        if (System.IO.File.Exists(oldUrlName))
        {
            System.IO.File.Move(oldUrlName, newUrlName);

            System.IO.File.Delete(oldUrlName);
        }
    }

    /// <summary>
    /// Places the currently selected node in rename mode.
    /// </summary>
    public void StartRename()
    {
        try
        {
            if (this.mytreeView.SelectedNode != null)
            {
                mytreeView.LabelEdit = true;
                mytreeView.SelectedNode.BeginEdit();
            }
        }
        catch (Exception ex) { MessageBox.Show(ex.Message); }
    }

    #endregion Rename

    /// <summary>
    /// treeView键盘操作
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void treeViewDirect_KeyDown(object sender, KeyEventArgs e)
    {
        //try
        //{
        if (e.KeyData == Keys.F2)
        {
            StartRename();
            e.SuppressKeyPress = true;
        }
        //else if (e.KeyData == Keys.F1)
        //{
        //    FormHelp formHelp = new FormHelp();
        //    formHelp.ShowDialog(this);
        //}
        else if (e.KeyData == Keys.F3)
        {
            ToolStripMenuItem_Click_add("txt");
        }
        else if (e.KeyData == Keys.F4)
        {
            createDirectory();
        }
        else if (e.KeyData == Keys.F5)
        {
            if (((ArrayList)mytreeView.SelectedNode.Tag)[1].ToString() == "d")
            {
                string d = (((ArrayList)mytreeView.SelectedNode.Tag)[0].ToString());
                if (Directory.Exists(d)) { Process.Start(d); }
            }
            else if (((ArrayList)mytreeView.SelectedNode.Tag)[1].ToString() == "f")
            {
                RunFile.open_system(((ArrayList)mytreeView.SelectedNode.Tag)[0].ToString());
            }
        }
        else if (e.KeyData == Keys.F6)
        {
            //if (((ArrayList)treeViewDirect.SelectedNode.Tag)[1].ToString() == "d")
            //{
            //    fangwen_file();
            //}
            //else
            //{
            //    fangwen(Path.GetExtension(treeViewDirect.SelectedNode.Text));
            //}
        }
        else if (e.KeyData == Keys.F7)
        {
            LoadDirAndFile(mytreeView.SelectedNode);
        }
        //else if (e.KeyData == Keys.F8)
        //{
        //    fangwenwangye();
        //}
        else if (e.KeyData == Keys.Delete)
        {
            try
            {
                FileCtrl.PutRececal(((ArrayList)mytreeView.SelectedNode.Tag)[0].ToString());
                TabControlHelp.CloseTabControlPage(this.tabControlCenter, TreeViewHelper.GetPath(mytreeView.SelectedNode));
                mytreeView.SelectedNode.Remove();
            }
            catch (Exception eee)
            {
                MessageBox.Show(eee.StackTrace);
            }
        }
        else if (e.Control && e.KeyCode == Keys.F8)
        {
            Console.Write("1");
        }
        else
        {
            string strPath = "Xml/openkey.xml";
            XmlDocument doc = new XmlDocument();
            doc.Load(strPath);
            XmlNodeList nodeList = doc.SelectSingleNode("data").ChildNodes;

            foreach (XmlNode xn in nodeList)
            {
                if (xn.Name == "row")
                {
                    if (xn["key"].InnerText == e.KeyData.ToString())
                    {
                        string soft = xn["rowpath"].InnerText;
                        Process.Start(soft, "\"" + TreeViewHelper.GetPath(mytreeView.SelectedNode) + "\"");

                        break;
                    }
                }
            }
        }
        //}
        //catch (Exception ee)
        //{
        //    MessageBox.Show(ee.ToString());
        //}
    }

    private static string get_openmypass(string type)
    {
        string strPath = "Xml/openmy.xml";
        XmlDocument doc = new XmlDocument();
        doc.Load(strPath);
        XmlNodeList nodeList = doc.SelectSingleNode("data").ChildNodes;

        foreach (XmlNode xn in nodeList)
        {
            if (xn.Name == "row")
            {
                if (xn["name"].InnerText.IndexOf(type) != -1)
                {
                    return xn["pass"].InnerText;
                    break;
                }
            }
        }

        return "";
    }

    private static string get_openmysoft(string type)
    {
        string strPath = "Xml/openmy.xml";
        XmlDocument doc = new XmlDocument();
        doc.Load(strPath);
        XmlNodeList nodeList = doc.SelectSingleNode("data").ChildNodes;

        foreach (XmlNode xn in nodeList)
        {
            if (xn.Name == "row")
            {
                if (xn["name"].InnerText.IndexOf(type) != -1)
                {
                    return xn["rowpath"].InnerText;
                    break;
                }
            }
        }

        return "";
    }

    private void openText(string Open, TreeNode treeNode, TabPage tp)
    {
        //*********************************************************
        //视频
        //*********************************************************
        if (Open == "mov")
        {
            //TabPage tp = new TabPage();
            tp.Text = treeNode.Text;
            tp.Tag = ((ArrayList)treeNode.Tag)[0].ToString();
            //tp.Show();

            this.tabControlCenter.SelectedTab = tp;
            this.tabControlCenter.Controls.Add(tp);

            //PictureBox pictureBox = new PictureBox();
            //pictureBox.Dock = DockStyle.Fill;

            //string img_fullname = ((ArrayList)treeNode.Tag)[0].ToString();
            //Image bb = new System.Drawing.Bitmap(img_fullname);

            //pictureBox.Image = (Image)bb;

            //pictureBox.SizeMode = PictureBoxSizeMode.Zoom;

            media.UserControlMediaElement u1 = new media.UserControlMediaElement();
            string fullname = ((ArrayList)treeNode.Tag)[0].ToString();
            u1.mysource = new Uri(fullname);
            u1.MediaOpened();
            System.Windows.Forms.Integration.ElementHost panel = new System.Windows.Forms.Integration.ElementHost();

            //release resource
            panel.Tag = "mov";
            //panel.AutoScroll = true;
            panel.Dock = DockStyle.Fill;
            panel.Child = u1;

            tp.Controls.Add(panel);
            tp.AutoScroll = true;
        }

        //*********************************************************
        //图片
        //*********************************************************
        else if (Open == "img")
        {
            //TabPage tp = new TabPage();
            tp.Text = treeNode.Text;
            tp.Tag = ((ArrayList)treeNode.Tag)[0].ToString();
            //tp.Show();

            this.tabControlCenter.SelectedTab = tp;
            this.tabControlCenter.Controls.Add(tp);

            PictureBox pictureBox = new PictureBox();
            pictureBox.Dock = DockStyle.Fill;

            string img_fullname = ((ArrayList)treeNode.Tag)[0].ToString();
            Image bb = new System.Drawing.Bitmap(img_fullname);

            //string img_name = Path.GetFileName(img_fullname);
            //string img_tempname = "temp\\" + img_name;

            //if (File.Exists(img_tempname)) {
            //    Image bb1 = new System.Drawing.Bitmap(img_tempname);
            //    bb1.Dispose();
            //    FileCtrl.DirectoryDelete(img_tempname);
            //}

            //bb.Save(img_tempname);
            //bb.Dispose();

            //bb = new System.Drawing.Bitmap(img_tempname);

            pictureBox.Image = (Image)bb;

            pictureBox.SizeMode = PictureBoxSizeMode.Zoom;

            Panel panel = new Panel();

            //release resource
            panel.Tag = "img";
            panel.AutoScroll = true;
            panel.Dock = DockStyle.Fill;
            panel.Controls.Add(pictureBox);

            tp.Controls.Add(panel);
            tp.AutoScroll = true;
        }

        //*********************************************************
        //网页
        //*********************************************************
        else if (Open == "ie")
        {
            //TabPage tp = new TabPage();
            tp.Text = treeNode.Text;
            tp.Tag = ((ArrayList)treeNode.Tag)[0].ToString();
            //tp.Show();

            this.tabControlCenter.SelectedTab = tp;
            this.tabControlCenter.Controls.Add(tp);

            //csExWB.cEXWB cEXWB1 = new csExWB.cEXWB();
            //cEXWB1.Dock = DockStyle.Fill;
            WebBrowser webBrowser = new WebBrowser();
            webBrowser.Dock = DockStyle.Fill;
            webBrowser.ScriptErrorsSuppressed = true;
            //webBrowser.Document.Window.Error += Window_Error;
            try
            {
                string strUrl = Path.GetFullPath(((ArrayList)treeNode.Tag)[0].ToString());
                //cEXWB1.LocationUrl = strUrl;
                webBrowser.Url = new Uri(strUrl);
            }
            catch (Exception ee)
            {
            }
            tp.Controls.Add(webBrowser);
            tp.AutoScroll = true;

            tp.Disposed += tp_Disposed_webBrowser;
        }

        //*********************************************************
        // 文本
        //*********************************************************
        else
        {
            //TabPage tp = new TabPage();
            tp.Text = treeNode.Text;

            TabPageTag tabPageTag = new TabPageTag();
            tabPageTag.type = "textbox";
            tabPageTag.filename = ((ArrayList)treeNode.Tag)[0].ToString();

            //tp.Tag = ((ArrayList)treeNode.Tag)[0].ToString();
            tp.Tag = tabPageTag;
            this.tabControlCenter.SelectedTab = tp;
            this.tabControlCenter.Controls.Add(tp);

            MyRichTextBox richTextBoxExtended = new MyRichTextBox();
            richTextBoxExtended.SelectionChanged += RichTextBoxExtended_SelectionChanged;

            string str_filename = ((ArrayList)treeNode.Tag)[0].ToString();

            ///
            /// 当年把u8编码的写成gb的不明白是为什么。
            /// 这样如果是网页可能会乱码
            /// 明白了u8load过来是乱码
            ///
            //if (EncodingType.GetType(str_filename) == Encoding.UTF8
            //    &&
            //    (
            //    Path.GetExtension(str_filename) == ".txt"
            //    ||
            //    Path.GetExtension(str_filename) == ".htm")
            //    )
            //{
            //    string text = System.IO.File.ReadAllText(str_filename,
            //           EncodingType.GetType(str_filename));

            //    //FileStream fs = new FileStream(str_filename, FileMode.OpenOrCreate);
            //    StreamWriter sw = new StreamWriter(str_filename, false, Encoding.Default);
            //    sw.Write(text);

            //    sw.Flush();
            //    sw.Close();
            //}
            ///
            //if (
            //Path.GetExtension(str_filename) == ".txt"
            //||
            //Path.GetExtension(str_filename) == ".htm")

            //{
            //    string text = System.IO.File.ReadAllText(str_filename,
            //           Encoding.UTF8);

            //    //FileStream fs = new FileStream(str_filename, FileMode.OpenOrCreate);
            //    StreamWriter sw = new StreamWriter(str_filename, false, Encoding.UTF8);

            //    //Encoding.GetEncoding("GB2312")
            //    sw.Write(text);

            //    sw.Flush();
            //    sw.Close();
            //}

            //string fileContent;
            //using (StreamReader reader = new StreamReader(str_filename, Encoding.UTF8))
            //{
            //    fileContent = reader.ReadToEnd();
            //}
            //richTextBoxExtended.Text = fileContent;

            richTextBoxExtended.LoadFile(str_filename, RichTextBoxStreamType.PlainText);

            richTextBoxExtended.strFilename = ((ArrayList)treeNode.Tag)[0].ToString();

            richTextBoxExtended.Dock = DockStyle.Fill;

            richTextBoxExtended.Multiline = true;

            richTextBoxExtended.WordWrap = false;

            //搜索滚动
            //richTextBoxExtended.KeyDown += button_gundong();

            tp.Controls.Add(richTextBoxExtended);
        }
    }

    private void RichTextBoxExtended_SelectionChanged(object sender, EventArgs e)
    {
        //throw new NotImplementedException();
        this.labelTishi.Text = (sender as RichTextBox).SelectedText.Length.ToString();
    }

    private void Window_Error(object sender, HtmlElementErrorEventArgs e)
    {
        //throw new NotImplementedException();
        e.Handled = true;
    }

    private void tp_Disposed_webBrowser(object sender, EventArgs e)
    {
        //throw new NotImplementedException();
        foreach (var cc in (sender as TabPage).Controls)
        {
            if (cc is WebBrowser)
            {
                (cc as WebBrowser).Dispose();
            }
        }
    }

    private void richTextBoxExtended_KeyDown(object sender, KeyEventArgs e)
    {
        //throw new NotImplementedException();
        //if (e.KeyCode == Keys.F && e.Modifiers == Keys.Control)
        //{
        //    this.textBoxSearch.Focus();
        //    this.radioButton3.Checked = true;
        //}
    }

    //private KeyEventHandler button_gundong(object sender, KeyEventArgs e)
    //{
    //    if (e.KeyCode == Keys.F3) {
    //        button_gundong_Click(null,null);
    //    }
    //}

    /// <summary>
    /// 加载
    /// </summary>
    /// <param name="treeNode"></param>
    private void LoadText(TreeNode treeNode)
    {
        string strUrl = Path.GetFullPath(((ArrayList)treeNode.Tag)[0].ToString());
        FileInfo fi = new FileInfo(strUrl);
        if (fi.Exists == false) { return; }

        //*********************************************************
        //text load 用了tp.Text = treeNode.Text;tp.Tag = ((ArrayList)treeNode.Tag)[0].ToString();两个属性
        //*********************************************************
        if (((ArrayList)treeNode.Tag)[1].ToString() != "d")
        {
            //*********************************************************
            //
            //*********************************************************
            foreach (TabPage tpTemp in tabControlCenter.Controls)
            {
                if ((tpTemp.Tag as TabPageTag) != null && ((tpTemp.Tag as TabPageTag).filename.ToString()) == ((ArrayList)treeNode.Tag)[0].ToString())
                {
                    this.tabControlCenter.SelectedTab = tpTemp;
                    return;
                }
            }

            TabPage tp = new TabPage();

            #region load

            //*********************************************************
            // paichu
            //*********************************************************
            //ArrayList array = new ArrayList();
            string strPath = Path.Combine(System.Windows.Forms.Application.StartupPath, "Xml/Img.xml");
            XmlDocument doc = new XmlDocument();
            doc.Load(strPath);
            XmlNodeList nodeList = doc.SelectSingleNode("data").ChildNodes;

            string Extension = "";
            string IsOpen = "";
            string Open = "";

            foreach (XmlNode xn in nodeList)
            {
                if (xn.Name == "row")
                {
                    foreach (XmlNode xn1 in xn.ChildNodes)
                    {
                        if (xn1.Name == "Extension")
                        {
                            IsOpen = "";
                            Open = "";
                            Extension = xn1.InnerText;
                        }
                        else if (xn1.Name == "IsOpen")
                        {
                            IsOpen = xn1.InnerText;
                        }
                        else if (xn1.Name == "Open")
                        {
                            Open = xn1.InnerText;
                        }
                    }

                    if (Path.GetExtension(treeNode.Text).ToLower() == Extension.ToString().ToLower())
                    {
                        if (IsOpen == "0")
                        {
                            return;
                        }
                        else
                        {
                            openText(Open, treeNode, tp);
                            return;
                        }
                    }
                }
            }

            openText("text", treeNode, tp);

            tp.ToolTipText = ((ArrayList)treeNode.Tag)[0].ToString().ToString();

            #endregion load
        }
    }

    /// <summary>
    ///家在目录所有文件
    /// </summary>
    private void LoadDirAndFileAll(TreeNode Node)
    {
        Node.Nodes.Clear();
        DirectoryInfo diRoot;
        diRoot = new DirectoryInfo(Path.Combine(((ArrayList)Node.Tag)[0].ToString(), ""));
        if (diRoot.Exists == false) { return; }

        mytreeView.BeginUpdate();

        iDirectories = AddDirectoriesAll(Node);
        iFiles = TreeViewHelper.AddFiles(Node);
        Node.Expand();

        mytreeView.EndUpdate();
    }

    /// <summary>
    /// 添加所有
    /// </summary>
    /// <param name="tnSubNode"></param>
    public int AddDirectoriesAll(TreeNode tnSubNode)
    {
        int iDirectories = 0;

        try
        {
            DirectoryInfo diRoot;
            diRoot = new DirectoryInfo(Path.Combine(((ArrayList)tnSubNode.Tag)[0].ToString(), ""));
            DirectoryInfo[] dirs = diRoot.GetDirectories();

            // Add the sub directories to the treeViewDirect
            foreach (DirectoryInfo dir in dirs)
            {
                if (dir.Name == ".svn")
                {
                    continue;
                }

                iDirectories++;
                TreeNode subNode = new TreeNode(dir.Name);

                subNode.ImageKey = "dirClose";
                subNode.SelectedImageKey = "dirOpen";

                ArrayList arrayListTag = new ArrayList();
                arrayListTag.Add(dir.FullName);
                arrayListTag.Add("d");
                subNode.Tag = arrayListTag;

                tnSubNode.Nodes.Add(subNode);

                LoadDirAndFileAll(subNode);
            }

            return iDirectories;
        }
        catch (Exception ee)
        {
            return 0;
        }
    }

    /// <summary>
    ///
    /// </summary>
    private void LoadDirAndFile(TreeNode Node)
    {
        Node.Nodes.Clear();
        DirectoryInfo diRoot;
        diRoot = new DirectoryInfo(Path.Combine(((ArrayList)Node.Tag)[0].ToString(), ""));
        if (diRoot.Exists == false) { return; }

        mytreeView.BeginUpdate();

        iDirectories = TreeViewHelper.AddDirectories(Node);
        iFiles = TreeViewHelper.AddFiles(Node);

        ///提示文件数量
        ///
        //this.labelTishi.Text = "file number:" + iFiles.ToString();
        this.labelTishi.Text = "" + iFiles.ToString();

        mytreeView.EndUpdate();

        mytreeView.SelectedNode.Expand();
        //statusBar.Text = iDirectories.ToString() + " Folder(s)  " + iFiles.ToString() + " File(s)";

        //    try
        //    {
        //}
        //catch (Exception ee)
        //{
        //    MessageBox.Show(ee.ToString());
        //}
    }

    /// <summary>
    /// 展开
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void treeViewDirect_AfterSelect(object sender, TreeViewEventArgs e)
    {
        try
        {
            //if (e.Action != TreeViewAction.ByMouse)
            //{
            //    return;
            //}

            //*********************************************************
            //direct load
            //*********************************************************
            // Must clear this first, else the directories will get duplicated in treeview
            if (((ArrayList)e.Node.Tag)[1].ToString() == "d")
            {
                LoadDirAndFile(e.Node);
            }

            //*********************************************************
            //text load
            //*********************************************************
            else
            {
                LoadText(e.Node);
            }

            this.mytreeView.Focus();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }

    #endregion

    #region 主菜单 事件

    /// <summary>
    /// 帮助
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    //private void 帮助ToolStripMenuItem_Click(object sender, EventArgs e)
    //{
    //    FormHelp formHelp = new FormHelp();
    //    formHelp.ShowDialog(this);
    //}

    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void close_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void refresh_Click(object sender, EventArgs e)
    {
        try
        {
            this.initRootNode();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }

    #endregion

    #region 快捷菜单 contextMenuStripTree 事件

    private void openFile(string strSoft)
    {
        try
        {
            if (mytreeView.SelectedNode.Tag.ToString() == "d") { return; }

            string sPath = TreeViewHelper.GetPath(mytreeView.SelectedNode);
            com.openFile(strSoft, sPath);
            //Process.Start(strSoft, Path.GetFullPath(sPath));
        }
        catch (Exception Exc) { MessageBox.Show(Exc.ToString()); }
    }

    ///// <summary>
    ///// Dreamweaver
    ///// </summary>
    ///// <param name="sender"></param>
    ///// <param name="e"></param>
    //private void 打开Dreamweaver8ToolStripMenuItem_Click(object sender, EventArgs e)
    //{
    //    openFile(strGreen + "\\Dreamweaver8\\Dreamweaver.exe");
    //}

    /// <summary>
    /// EditPlus
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void 打开EditplustoolStripMenuItem_Click(object sender, EventArgs e)
    {
        openFile(strGreen + "\\EditPlus 2\\editplus.exe");
    }

    ///// <summary>
    /////
    ///// </summary>
    ///// <param name="sender"></param>
    ///// <param name="e"></param>
    //private void 打开PhotoshopToolStripMenuItem_Click_1(object sender, EventArgs e)
    //{
    //    openFile(strGreen + "\\Adobe Photoshop CS4\\Photoshop.exe");
    //}

    //private void 打开Pdg超星ToolStripMenuItem_Click(object sender, EventArgs e)
    //{
    //    openFile(strGreen + "\\SSREADER\\SsReader.exe");
    //}

    //private void 打开暴风影音ToolStripMenuItem_Click(object sender, EventArgs e)
    //{
    //    openFile(strGreen + "\\GreenMPC\\GreenMPC.exe");
    //}

    //private void 打开WinmergetoolStripMenuItem_Click(object sender, EventArgs e)
    //{
    //    openFile(strGreen + "\\WinMergePortable\\WinMergePortable.exe");
    //}

    /// <summary>
    /// 排序
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void ToolStripMenuItemSort_Click(object sender, EventArgs e)
    {
        this.mytreeView.TreeViewNodeSorter = new NodeSorter();
    }

    private void open_system()
    {
        try
        {
            if (this.mytreeView.SelectedNode == null)
            {
                MessageBox.Show("没有选中节点");
                return;
            }

            string dirctery = TreeViewHelper.GetPath(this.mytreeView.SelectedNode);
            Process.Start(dirctery);
        }
        catch (Exception ex) { }
    }

    /// <summary>
    /// 打开文件夹
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void 打开文件夹ToolStripMenuItem_Click(object sender, EventArgs e)
    {
        open_system();
    }

    /// <summary>
    /// EmEditor
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void 打开EmEditorToolStripMenuItem1_Click(object sender, EventArgs e)
    {
        openFile(strGreen + "\\EmEditor\\EmEditor.exe");
    }

    private void 编译JavaToolStripMenuItem_Click(object sender, EventArgs e)
    {
        string soft = strGreen + "\\java\\java.bat";
        string sPath = TreeViewHelper.GetPath(mytreeView.SelectedNode);

        string dir = Path.GetDirectoryName(sPath);
        string driver = Directory.GetDirectoryRoot(sPath);
        string file = Path.GetFileName(sPath);
        string fileWithoutExtension = Path.GetFileNameWithoutExtension(sPath);

        Encoding encode = Encoding.Default;

        StreamReader sr = new StreamReader(soft);
        string temp = sr.ReadToEnd();

        temp = temp.Replace("$dir", dir);
        temp = temp.Replace("$driver", driver);
        temp = temp.Replace("$fileWithoutExtension", fileWithoutExtension);
        temp = temp.Replace("$file", file);

        StreamWriter sw = new StreamWriter(strGreen + "\\java\\temp.bat", false, encode);
        sw.Write(temp);
        sw.Flush();
        sw.Close();

        Process.Start(strGreen + "\\java\\temp.bat");
    }

    private void 运行PhpToolStripMenuItem_Click(object sender, EventArgs e)
    {
        string strPort;
        string strRootpath;
        ParseXml.get_php_run(out strPort, out strRootpath);

        string sPath = TreeViewHelper.GetPath(mytreeView.SelectedNode);

        if (strPort == "") { strPort = "80"; }
        sPath = (sPath.Substring(sPath.IndexOf(strRootpath) + strRootpath.Length, sPath.Length - sPath.IndexOf(strRootpath) - strRootpath.Length)).Replace("\\", "/");

        string url = "http://localhost:" + strPort + "//" + sPath;
        System.Diagnostics.Process.Start(url);
    }

    private void 运行NetToolStripMenuItem_Click(object sender, EventArgs e)
    {
        string strPort = "";

        strPort = ParseXml.get_net_run_port();

        if (((ArrayList)mytreeView.SelectedNode.Tag)[1].ToString() == "d")
        {
            string d = Path.GetFullPath((((ArrayList)mytreeView.SelectedNode.Tag)[0]).ToString());
            if (Directory.Exists(d))
            {
                bianyi b = bianyi_factory.get_bianyi("net");
                b.work(d);
            }

            string url = "http://localhost:" + strPort;
            System.Diagnostics.Process.Start(url);
        }
        else if (((ArrayList)mytreeView.SelectedNode.Tag)[1].ToString() == "f")
        {
        }
    }

    private void 打开PdfToolStripMenuItem_Click(object sender, EventArgs e)
    {
        openFile(strGreen + "\\PDF\\PDFXCview.exe");
    }

    private void 编译CToolStripMenuItem_Click(object sender, EventArgs e)
    {
        string soft = strGreen + "\\c++\\c++.bat";
        string sPath = TreeViewHelper.GetPath(mytreeView.SelectedNode);

        string dir = Path.GetDirectoryName(sPath);
        string driver = Directory.GetDirectoryRoot(sPath);

        driver = driver.Replace("\\", "");

        string file = Path.GetFileName(sPath);
        string fileWithoutExtension = Path.GetFileNameWithoutExtension(sPath);

        Encoding encode = Encoding.Default;

        StreamReader sr = new StreamReader(soft);
        string temp = sr.ReadToEnd();

        temp = temp.Replace("$dir", dir);
        temp = temp.Replace("$driver", driver);
        temp = temp.Replace("$fileWithoutExtension", fileWithoutExtension);
        temp = temp.Replace("$file", file);

        StreamWriter sw = new StreamWriter(strGreen + "\\c++\\temp.bat", false, encode);
        sw.Write(temp);
        sw.Flush();
        sw.Close();

        Process.Start(strGreen + "\\c++\\temp.bat");
    }

    private void 编译PhpToolStripMenuItem_Click(object sender, EventArgs e)
    {
        编译php();
    }

    private void 编译php()
    {
        string soft = strGreen + "\\php\\php.bat";
        string sPath = TreeViewHelper.GetPath(mytreeView.SelectedNode);

        string php = Path.GetFullPath(strGreen + @"\APMServ5.2.6\PHP\php.exe");
        php = "\"" + php + "\"";

        string dir = Path.GetDirectoryName(sPath);
        string driver = Directory.GetDirectoryRoot(sPath);
        string file = Path.GetFileName(sPath);
        file = "\"" + file + "\"";

        string fileWithoutExtension = Path.GetFileNameWithoutExtension(sPath);

        Encoding encode = Encoding.Default;

        StreamReader sr = new StreamReader(soft);
        string temp = sr.ReadToEnd();

        temp = temp.Replace("$php", php);

        temp = temp.Replace("$dir", dir);
        temp = temp.Replace("$driver", driver);
        temp = temp.Replace("$fileWithoutExtension", fileWithoutExtension);
        temp = temp.Replace("$file", file);

        StreamWriter sw = new StreamWriter(strGreen + "\\php\\temp.bat", false, encode);
        sw.Write(temp);
        sw.Flush();
        sw.Close();

        Process ps = new Process();
        ps.StartInfo.FileName = strGreen + "\\php\\temp.bat";
        ps.Start();

        //Process.Start(("\\php\\temp.bat");
    }

    private void 编译PerlToolStripMenuItem_Click(object sender, EventArgs e)
    {
        string soft = strGreen + "\\perl\\perl.bat";
        string sPath = TreeViewHelper.GetPath(mytreeView.SelectedNode);

        string dir = Path.GetDirectoryName(sPath);
        string driver = Directory.GetDirectoryRoot(sPath);
        string file = Path.GetFileName(sPath);
        string fileWithoutExtension = Path.GetFileNameWithoutExtension(sPath);

        Encoding encode = Encoding.Default;

        StreamReader sr = new StreamReader(soft);
        string temp = sr.ReadToEnd();

        temp = temp.Replace("$dir", dir);
        temp = temp.Replace("$driver", driver);
        //temp = temp.Replace("$fileWithoutExtension", fileWithoutExtension);
        temp = temp.Replace("$file", file);

        StreamWriter sw = new StreamWriter(strGreen + "\\perl\\temp.bat", false, encode);
        sw.Write(temp);
        sw.Flush();
        sw.Close();

        Process ps = new Process();
        ps.StartInfo.FileName = strGreen + "\\perl\\temp.bat";
        ps.Start();
    }

    /// <summary>
    /// mysql
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void mysqlToolStripMenuItem_Click(object sender, EventArgs e)
    {
    }

    /// <summary>
    ///
    /// </summary>
    private void fangwenwangye()
    {
        TreeNode treeNode = mytreeView.SelectedNode;
        string sPath = TreeViewHelper.GetPath(treeNode);

        StreamReader fi = new StreamReader(sPath);

        string s = fi.ReadLine();
        while (s.Trim() == "" && fi.EndOfStream == false)
        {
            s = fi.ReadLine();
        }

        string url = s.Trim();

        create_tabpage_wangye(treeNode, url);
        fi.Close();
    }

    private void fangwenrss()
    {
        try
        {
            string soft = get_openmysoft(".rss");

            TreeNode treeNode = mytreeView.SelectedNode;
            string sPath = TreeViewHelper.GetPath(treeNode);

            StreamReader fi = new StreamReader(sPath);
            string s = fi.ReadLine();
            string url = s.Trim();

            //string soft = @"..\\@green\my\数据库综合\WindowsFormsApplication1.exe";
            //E:\all\My DBank\codecontent\now\2011-03-05 nmoa数据导入导出\2011-03-10 1.0\WindowsFormsApplication1\bin\Debug
            //string soft = @"E:\all\My DBank\codecontent\now\2011-07-29 rss\2.0\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe";

            Process ps = new Process();
            ps.StartInfo.FileName = soft;
            ps.StartInfo.Arguments = url;

            ps.Start();

            //expend_rss(treeNode, url);
            fi.Close();
        }
        catch (Exception ee) { }
    }

    private SyndicationFeed feed;
    private bool flag;

    private void responseReady(IAsyncResult asyncResult)
    {
        try
        {
            System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = true;
            WebRequest request = (WebRequest)asyncResult.AsyncState;
            WebResponse response = (WebResponse)request.EndGetResponse(asyncResult);
            XmlReader reader = XmlReader.Create(response.GetResponseStream());
            feed = SyndicationFeed.Load(reader);
            //PostsList.DataSource = feed.Items;
            //PostsList.DisplayMember = "Title.Text";

            flag = true;
        }
        catch (Exception ee)
        {
            flag = true;
            MessageBox.Show(ee.ToString());
        }
    }

    private void expend_rss(TreeNode treeNode, string url)
    {
        Uri uri = new Uri(url);
        WebRequest request = (WebRequest)WebRequest.Create(uri);
        request.BeginGetResponse(new AsyncCallback(responseReady), request);
        flag = false;

        while (feed == null && flag == false)
        {
            Thread.Sleep(1000);
        }
        if (feed != null)
        {
            treeNode.Nodes.Clear();
            foreach (SyndicationItem item in feed.Items)
            {
                TreeNode treeNode1 = new TreeNode();
                treeNode1.Text = item.Title.Text + " " + item.PublishDate.ToLocalTime();
                //treeNode1.Tag = item;
                ArrayList arrayListTag = new ArrayList();
                arrayListTag.Add(item);
                arrayListTag.Add("rss");
                treeNode1.Tag = arrayListTag;

                treeNode.Nodes.Add(treeNode1);
            }
            treeNode.Expand();
        }
    }

    private void create_tabpage_rss(TreeNode treeNode, SyndicationItem item)
    {
        WebBrowser webBrowser1 = new WebBrowser();
        webBrowser1.DocumentText = item.Summary.Text;
        webBrowser1.Dock = DockStyle.Fill;

        Panel panel = new Panel();

        panel.Tag = "wangye";
        panel.AutoScroll = true;
        panel.Dock = DockStyle.Fill;
        panel.Controls.Add(webBrowser1);

        TabPage tp = new TabPage();
        tp.Text = treeNode.Text;
        tp.Tag = ((ArrayList)treeNode.Tag)[0].ToString();
        this.tabControlCenter.SelectedTab = tp;
        this.tabControlCenter.Controls.Add(tp);

        //tp.Controls.Add(webBrowser1);
        tp.Controls.Add(panel);
        tp.AutoScroll = true;
    }

    private void create_tabpage_wangye(TreeNode treeNode, string url)
    {
        WebBrowser webBrowser1 = new WebBrowser();
        webBrowser1.ScriptErrorsSuppressed = true;
        webBrowser1.Url = new Uri(url.Trim());
        webBrowser1.Dock = DockStyle.Fill;

        Panel panel = new Panel();

        panel.Tag = "wangye";
        panel.AutoScroll = true;
        panel.Dock = DockStyle.Fill;
        panel.Controls.Add(webBrowser1);

        TabPage tp = new TabPage();
        tp.Text = treeNode.Text;
        tp.Tag = ((ArrayList)treeNode.Tag)[0].ToString();
        this.tabControlCenter.SelectedTab = tp;
        this.tabControlCenter.Controls.Add(tp);

        //tp.Controls.Add(webBrowser1);
        tp.Controls.Add(panel);
        tp.AutoScroll = true;
    }

    private void create_tabpage_rss(TreeNode treeNode, string url)
    {
        WebBrowser webBrowser1 = new WebBrowser();
        webBrowser1.Url = new Uri(url.Trim());
        webBrowser1.Dock = DockStyle.Fill;

        Panel panel = new Panel();

        panel.Tag = "wangye";
        panel.AutoScroll = true;
        panel.Dock = DockStyle.Fill;
        panel.Controls.Add(webBrowser1);

        TabPage tp = new TabPage();
        tp.Text = treeNode.Text;
        tp.Tag = ((ArrayList)treeNode.Tag)[0].ToString();
        this.tabControlCenter.SelectedTab = tp;
        this.tabControlCenter.Controls.Add(tp);

        //tp.Controls.Add(webBrowser1);
        tp.Controls.Add(panel);
        tp.AutoScroll = true;
    }

    private void create_tabpage_wangye(string text, string url)
    {
        //ChromiumWebBrowser webBrowser1 = new ChromiumWebBrowser(url);
        //WebBrowser webBrowser1 = new WebBrowser();

        ////webBrowser1.Navigate("about:blank");
        ////while (!(webBrowser1.ReadyState == System.Windows.Forms.WebBrowserReadyState.Complete)) {
        ////    Application.DoEvents();
        ////}
        ////webBrowser1.Url = new Uri(url.Trim());
        ////webBrowser1.Url = new Uri(@"https://www.toutiao.com/");
        ////webBrowser1.Navigate("https://www.baidu.com/baidu?tn=baidu&&word=1");

        ////url = @"https://so.toutiao.com/search?dvpf=pc&source=input&keyword=111";
        //string encodedUrl = Uri.EscapeUriString(url);

        //webBrowser1.Navigate(encodedUrl.Trim());
        //webBrowser1.Dock = DockStyle.Fill;
        //webBrowser1.ScriptErrorsSuppressed = true;

        WebView webBrowser1 = new WebView
        {
            Dock = DockStyle.Fill,
            Url = url
        };



        Panel panel = new Panel();

        panel.Tag = "wangye";
        panel.AutoScroll = true;
        panel.Dock = DockStyle.Fill;
        panel.Controls.Add(webBrowser1);

        TabPage tp = new TabPage();
        tp.Text = text;
        tp.Tag = text;
        this.tabControlCenter.SelectedTab = tp;
        this.tabControlCenter.Controls.Add(tp);

        //tp.Controls.Add(webBrowser1);
        tp.Controls.Add(panel);
        tp.AutoScroll = true;

        //tp.Disposed += tp_Disposed_webBrowser;
        //webBrowser1.Refresh();
        //webBrowser1.Navigate("https://www.baidu.com/baidu?tn=baidu&&word=1");
        //webBrowser1.Refresh();
        //string ss = url;
        //webBrowser1.Navigate(ss);
    }

    private void toolStripMenuItemfangwen_Click(object sender, EventArgs e)
    {
        try
        {
            fangwenwangye();
        }
        catch (Exception ee) { }
    }

    #endregion

    #region 快捷菜单 contextMenuStripTab 事件

    /// <summary>
    /// 其他
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void 关闭其他ToolStripMenuItem_Click(object sender, EventArgs e)
    {
        try
        {
            ArrayList al = new ArrayList();

            foreach (Control control in this.tabControlCenter.TabPages)
            {
                if (control != this.tabControlCenter.SelectedTab)
                {
                    al.Add(control);
                }
            }

            foreach (object o in al)
            {
                if (((TabPage)o).Controls[0] != null)
                {
                    closeTab((TabPage)o);
                }

                ((Control)o).Dispose();
            }
        }
        catch { }
    }

    /// <summary>
    /// 关闭所有
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void toolStripMenuItemClose_Click(object sender, EventArgs e)
    {
        //this.tabControlCenter.Controls.Clear();

        foreach (TabPage tp in tabControlCenter.TabPages)
        {
            closeTab(tp);
        }

        this.tabControlCenter.TabPages.Clear();

        curhistory = null;
        GC.Collect();
    }

    #endregion

    /// <summary>
    /// 添加文件
    /// </summary>
    /// <param name="leixing"></param>
    private void ToolStripMenuItem_Click_add(string leixing)
    {
        try
        {
            if (((ArrayList)this.mytreeView.SelectedNode.Tag)[1].ToString() == "d")
            {
                string path = ((ArrayList)this.mytreeView.SelectedNode.Tag)[0].ToString();
                add a = add_factory.get_add(leixing);
                a.create_file(path);

                TreeNode tnNew = new TreeNode(a.filename);

                ArrayList arrayListTag = new ArrayList();
                arrayListTag.Add(a.filepath);
                arrayListTag.Add("f");
                tnNew.Tag = arrayListTag;

                TreeViewHelper.ChangeFileIco(tnNew);

                mytreeView.SelectedNode.Nodes.Add(tnNew);
                mytreeView.SelectedNode = tnNew;

                //LoadText(tnNew);
            }
            else
            {
                MessageBox.Show("从文件夹建立文件");
            }
        }
        catch (Exception ee)
        {
        }
    }

    private void 通讯录ToolStripMenuItem_Click(object sender, EventArgs e)
    {
        ToolStripMenuItem_Click_add("tongxunlu");
    }

    private void sqlToolStripMenuItem_Click(object sender, EventArgs e)
    {
        ToolStripMenuItem_Click_add("sql");
    }

    private void cToolStripMenuItem_Click(object sender, EventArgs e)
    {
        ToolStripMenuItem_Click_add("c#");
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void buttonFanyi_Click(object sender, EventArgs e)
    {
        string s = textBoxSearch.Text;
        string from = "en";
        string to = "zh";

        Match m = Regex.Match(s, "[\u4e00-\u9fa5]");
        if (m.Success)
        {
            from = "zh";
            to = "en";
        }

        TabPage tp = new TabPage();
        tp.Text = "@@Temp";
        tp.Tag = "null";

        this.tabControlCenter.Controls.Add(tp);
        this.tabControlCenter.SelectedTab = tp;

        MyRichTextBox richTextBoxExtended = new MyRichTextBox();
        //richTextBoxExtended.KeyDown += richTextBoxExtended_KeyDown;

        richTextBoxExtended.Text = common.translate.fanyi.GetGoogtextStr(s, from, to);
        richTextBoxExtended.Dock = DockStyle.Fill;

        tp.Controls.Add(richTextBoxExtended);
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    //private void 时间ToolStripMenuItem_Click(object sender, EventArgs e)
    //{
    //    FormTime ft = new FormTime();
    //    //ft.ShowDialog(this);
    //    ft.Show();

    //    // coding.UserControl1.sho.
    //}

    private void toolStripMenuItem6_Click(object sender, EventArgs e)
    {
        open_form_send();
    }

    private void open_form_send()
    {
        TreeNode tn = this.mytreeView.SelectedNode;
        //string file_path = tn.FullPath;

        string file_path = TreeViewHelper.GetPath(tn);

        StreamReader sr = new StreamReader(file_path);
        bool isurl = false;
        bool ispost = false;
        bool ismethod = false;
        bool isimg = false;
        bool isencoding = false;

        string url = "";
        string post = "";
        string method = "";
        string encoding = "";

        while (!sr.EndOfStream)
        {
            string temp = sr.ReadLine();
            if (!string.IsNullOrEmpty(temp.Trim()))
            {
                if (temp.IndexOf("url:") != -1)
                {
                    isurl = true;
                }
                else if (temp.IndexOf("post:") != -1)
                {
                    ispost = true;
                    isurl = false;
                }
                else if (temp.IndexOf("method:") != -1)
                {
                    ismethod = true;
                    ispost = false;
                    isurl = false;
                }
                else if (temp.IndexOf("img:") != -1)
                {
                    isimg = true;
                }
                else if (temp.IndexOf("encoding:") != -1)
                {
                    isencoding = true;
                }
                else if (isencoding)
                {
                    encoding = temp.Trim();
                    isencoding = false;
                }
                else if (isurl)
                {
                    url = temp.Trim();
                    isurl = false;
                }
                else if (ispost)
                {
                    post += temp.Trim();
                }
                else if (ismethod)
                {
                    method = temp.Trim();
                    ismethod = false;
                }
            }
        }
        sr.Close();

        //string soft = @"..\\@green\my\数据库综合\WindowsFormsApplication1.exe";
        //E:\all\My DBank\codecontent\now\2011-03-05 nmoa数据导入导出\2011-03-10 1.0\WindowsFormsApplication1\bin\Debug
        //string soft = @"E:\all\My DBank\codecontent\now\2011-07-29 网页分析工具\代码\2.0\WindowsApplication1\bin\Debug\WindowsApplication1.exe";
        string soft = get_openmysoft(".url");

        string sPath = TreeViewHelper.GetPath(mytreeView.SelectedNode);

        string temp1 = url + "\n" + post + "\n" + method + "\n" + isimg + "\n" + encoding + "";
        sr.Close();

        Process ps = new Process();
        ps.StartInfo.FileName = soft;
        ps.StartInfo.Arguments = temp1;

        ps.Start();

        //Form_send fs = new Form_send();

        //fs.url = url;
        //fs.post = post;
        //fs.method = method;
        //fs.isimg = isimg;
        //fs.encoding = encoding;
        //fs.Show();
    }

    private void toolStripMenuItem7_Click(object sender, EventArgs e)
    {
        fangwenrss();
    }

    private void toolStripMenuItem2_Click(object sender, EventArgs e)
    {
        fangwen_database();
    }

    private void fangwen_database()
    {
        //string soft = @"..\\@green\my\数据库综合\WindowsFormsApplication1.exe";
        //E:\all\My DBank\codecontent\now\2011-03-05 nmoa数据导入导出\2011-03-10 1.0\WindowsFormsApplication1\bin\Debug
        //string soft = @"E:\all\My DBank\codecontent\now\2010-01-29 数据库综合\代码\2011-03-10 2.0\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe";
        string soft = get_openmysoft(".dbc");

        string sPath = TreeViewHelper.GetPath(mytreeView.SelectedNode);

        string dir = Path.GetDirectoryName(sPath);
        string driver = Directory.GetDirectoryRoot(sPath);
        string file = Path.GetFileName(sPath);
        string fileWithoutExtension = Path.GetFileNameWithoutExtension(sPath);

        Encoding encode = Encoding.Default;

        StreamReader sr = new StreamReader(sPath);
        string temp = sr.ReadToEnd();
        sr.Close();

        Process ps = new Process();
        ps.StartInfo.FileName = soft;
        ps.StartInfo.Arguments = temp;

        ps.Start();
    }

    /// <summary>
    /// f6 打开
    /// </summary>
    /// <param name="houzhui"></param>
    private void fangwen(string houzhui)
    {
        if (houzhui == ".cs")
        {
            编译cc();
            return;
        }
        else if (houzhui == ".php")
        {
            编译php();
            return;
        }
        else if (houzhui == ".rsp")
        {
            编译rsp();
        }
        else
        {
            open_mysoft(houzhui);
        }
    }

    /// <summary>
    /// 用自己的软件打开文件
    /// </summary>
    /// <param name="houzhui"></param>
    private void open_mysoft(string houzhui)
    {
        string soft = get_openmysoft(houzhui);
        string pass = get_openmypass(houzhui);
        string temp = "";

        string sPath = TreeViewHelper.GetPath(mytreeView.SelectedNode);
        Encoding encode = Encoding.Default;
        if (pass == "content")
        {
            StreamReader sr = new StreamReader(sPath, encode);
            temp = sr.ReadToEnd();
            sr.Close();
        }
        else
        {
            temp = sPath;
        }

        Process ps = new Process();
        ps.StartInfo.FileName = soft;
        ps.StartInfo.Arguments = temp;

        ps.Start();
        if (ps.HasExited)//判断是否运行结束
            ps.Kill();
    }

    private void fangwen_file()
    {
        string soft = get_openmysoft("d");
        string sPath = TreeViewHelper.GetPath(mytreeView.SelectedNode);
        string temp = sPath;
        Process ps = new Process();
        ps.StartInfo.FileName = soft;
        ps.StartInfo.Arguments = temp;
        ps.Start();
    }

    private void tabControlCenter_ControlAdded(object sender, ControlEventArgs e)
    {
        //history_add(e.Control as TabPage);
        //add_history(tabControlCenter.SelectedTab);
    }

    private void history_add(TabPage t)
    {
        //如果没有历史 加
        if (curhistory == null)
        {
            history h = new history();
            h.pre = null;
            h.node = t;
            h.next = null;
            curhistory = h;
            headhistory = h;
            tailhistory = h;
        }
        //如果有
        else if (t != null)
        {
            history h = new history();
            h.node = t;
            //h.next = null;

            tailhistory.next = h;
            h.pre = tailhistory;

            curhistory = h;
            tailhistory = h;
            //if (headhistory.next == null)
            //{
            //    headhistory.next = h;
            //}
        }

        //if (!ltp.Contains(t))
        //{
        //    ltp.Add(t);
        //    if (ltp.Count > 10)
        //    {
        //        ltp.RemoveAt(0);
        //    }

        //    cur = ltp.Count - 1;
        //}
        //else
        //{
        //    cur = ltp.IndexOf(t);
        //}
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void toolStripMenuItem8_Click(object sender, EventArgs e)
    {
        history_back();
    }

    private void history_back()
    {
        try
        {
            while (curhistory.pre != null)
            {
                if (curhistory.pre.node != null)
                {
                    //tabControlCenter.SelectedTab = curhistory.pre.node;

                    curhistory = curhistory.pre;
                    break;
                }
            }
        }
        catch (Exception)
        {
            //throw;
        }
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void toolStripMenuItem9_Click(object sender, EventArgs e)
    {
        history_next();
    }

    private void history_next()
    {
        try
        {
            while (curhistory.next != null)
            {
                if (curhistory.next.node != null)
                {
                    //tabControlCenter.SelectedTab = curhistory.next.node;
                    curhistory = curhistory.next;

                    break;
                }
            }
        }
        catch (Exception)
        {
            //throw;
        }
    }

    /// <summary>
    /// 在tab变换事件标志位清空.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void tabControlCenter_SelectedIndexChanged(object sender, EventArgs e)
    {
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void tabControlCenter_ControlRemoved(object sender, ControlEventArgs e)
    {
        history_del();
    }

    /// <summary>
    /// 选择一页的时候 选择页是cur
    /// 前一步 后一步可能是空 跳过 这样就可以不遍历了
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void tabControlCenter_Selected(object sender, TabControlEventArgs e)
    {
        oldtabpage = currenttabpage;
        currenttabpage = this.tabControlCenter.SelectedTab;
    }

    /// <summary>
    /// 编译c#
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void 编译ccToolStripMenuItem_Click(object sender, EventArgs e)
    {
        编译cc();
    }

    private void 编译cc()
    {
        string soft = strGreen + "\\c#\\c#.bat";
        string sPath = TreeViewHelper.GetPath(mytreeView.SelectedNode);

        string dir = Path.GetDirectoryName(sPath);
        string driver = Directory.GetDirectoryRoot(sPath);
        if (driver.Substring(driver.Length - 1, 1) == "\\")
        {
            driver = driver.Substring(0, driver.Length - 1);
        }
        string file = Path.GetFileName(sPath);
        string fileWithoutExtension = Path.GetFileNameWithoutExtension(sPath);

        Encoding encode = Encoding.Default;

        StreamReader sr = new StreamReader(soft);
        string temp = sr.ReadToEnd();

        temp = temp.Replace("$dir", dir);
        temp = temp.Replace("$driver", driver);
        temp = temp.Replace("$fileWithoutExtension", fileWithoutExtension);
        temp = temp.Replace("$file", file);

        StreamWriter sw = new StreamWriter(strGreen + "\\c#\\temp.bat", false, encode);
        sw.Write(temp);
        sw.Flush();
        sw.Close();

        Process.Start(strGreen + "\\c#\\temp.bat");
    }

    private void 编译rsp()
    {
        string soft = strGreen + "\\c#\\rsp.bat";
        string sPath = TreeViewHelper.GetPath(mytreeView.SelectedNode);

        string dir = Path.GetDirectoryName(sPath);
        string driver = Directory.GetDirectoryRoot(sPath);
        if (driver.Substring(driver.Length - 1, 1) == "\\")
        {
            driver = driver.Substring(0, driver.Length - 1);
        }
        string file = Path.GetFileName(sPath);
        string fileWithoutExtension = Path.GetFileNameWithoutExtension(sPath);

        Encoding encode = Encoding.Default;

        StreamReader sr = new StreamReader(soft);
        string temp = sr.ReadToEnd();

        temp = temp.Replace("$dir", dir);
        temp = temp.Replace("$driver", driver);
        temp = temp.Replace("$fileWithoutExtension", fileWithoutExtension);
        temp = temp.Replace("$file", file);

        StreamWriter sw = new StreamWriter(strGreen + "\\c#\\temp.bat", false, encode);
        sw.Write(temp);
        sw.Flush();
        sw.Close();

        Process.Start(strGreen + "\\c#\\temp.bat");
    }

    private void tabControlCenter_MouseClick(object sender, MouseEventArgs e)
    {
    }

    private void textBoxSearch_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            search();
        }
        else if (e.KeyCode == Keys.F3)
        {
            //button_gundong_Click(null, null);
            guandong();
        }
    }

    private void tabControlCenter_KeyDown(object sender, KeyEventArgs e)
    {
        //if (e.Control && e.KeyCode == Keys.Left)
        //{
        //    history_back();
        //}
        //else if (e.Control && e.KeyCode == Keys.Right)
        //{
        //    history_next();
        //}

        //if (e.Control && e.KeyCode == Keys.Delete)
        //{
        //    tab_del();
        //}
    }

    private void FormMain_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Alt && e.KeyCode == Keys.Q)
        {
            tab_del();
            e.SuppressKeyPress = true;
            return;
        }
        else if (e.Control && e.KeyCode == Keys.F)
        {
            this.textBoxSearch.Focus();
            this.radioButton3.Checked = true;

            return;
        }
        else if (e.Control && e.KeyCode == Keys.B)
        {
            this.textBoxSearch.Focus();
            this.radioButton1.Checked = true;

            return;
        }
        else if (e.Control && e.KeyCode == Keys.L)
        {
            this.textBoxSearch.Focus();
            this.radioButton2.Checked = true;

            return;
        }
        else if (e.Control && e.KeyCode == Keys.D)
        {
            this.textBoxdofunction.Focus();
            //this.radioButton2.Checked = true;

            return;
        }
        else if (e.Control && e.KeyCode == Keys.E)
        {
            //foreach (TabPage tpTemp in tabControlCenter.Controls)
            //{
            //    if (tpTemp.Tag.ToString() == "text")
            //    {
            //        this.tabControlCenter.SelectedTab = tpTemp;
            //        return;
            //    }
            //}

            if (this.tabControlCenter.SelectedTab != null)
            {
                var tb1 = this.tabControlCenter.SelectedTab;
                if (tb1.Controls.Count > 0)
                {
                    if (tb1.Controls[0].Tag == null)
                    {
                        var a = tb1.Controls[0] as MyRichTextBox;
                        //int i = a.Text.Length;
                        //int len = 300;
                        //Random r = new Random();
                        //if (i - 300 >= 0)
                        //{
                        //    int start = r.Next(1, i - len);
                        //    a.Select(start, len);
                        //    a.SelectionColor = Color.Red;
                        //    a.ScrollToCaret();
                        //}

                        a.Select(0, 0);
                        a.ScrollToCaret();
                    }
                }
            }

            return;
        }
        else if (e.KeyCode == Keys.F1)
        {
            //FormHelp formHelp = new FormHelp();
            //formHelp.ShowDialog(this);

            foreach (TabPage tpTemp in tabControlCenter.Controls)
            {
                if ((tpTemp.Tag.ToString()) == "f1")
                {
                    this.tabControlCenter.SelectedTab = tpTemp;
                    return;
                }
            }

            TabPage tp = new TabPage();
            tp.Text = "f1";
            tp.Tag = "f1";
            this.tabControlCenter.SelectedTab = tp;
            this.tabControlCenter.Controls.Add(tp);

            MyRichTextBox richTextBoxExtended = new MyRichTextBox();
            //richTextBoxExtended.KeyDown += richTextBoxExtended_KeyDown;

            richTextBoxExtended.LoadFile("xml/help.txt", RichTextBoxStreamType.PlainText);
            richTextBoxExtended.strFilename = "xml/help.txt";
            richTextBoxExtended.Dock = DockStyle.Fill;

            richTextBoxExtended.Multiline = true;

            richTextBoxExtended.WordWrap = false;

            tp.Controls.Add(richTextBoxExtended);
        }
        //else if (e.Control && e.KeyCode == Keys.Delete) { }
        //MessageBox.Show("bangzhu");
        else if (e.KeyCode == Keys.F2)
        {
            //foreach (Control a in this.Controls)
            //{
            if (this.mytreeView.Focused == true)
            {
                return;
            }
            //}
            string filename = data.xml.xml_help.get_time();
            string name = Path.GetFileName(filename);

            foreach (TabPage tpTemp in tabControlCenter.Controls)
            {
                if (tpTemp.Tag != null && tpTemp.Tag is common.TabPageTag && (tpTemp.Tag as common.TabPageTag).filename == filename)
                {
                    this.tabControlCenter.SelectedTab = tpTemp;
                    return;
                }
            }

            TabPage tp = new TabPage();
            tp.Text = name;
            //tp.Tag = filename;

            TabPageTag tabPageTag = new TabPageTag();
            tabPageTag.type = "textbox";
            tabPageTag.filename = filename;
            tp.Tag = tabPageTag;

            this.tabControlCenter.SelectedTab = tp;
            this.tabControlCenter.Controls.Add(tp);

            MyRichTextBox richTextBoxExtended = new MyRichTextBox();
            //richTextBoxExtended.KeyDown += richTextBoxExtended_KeyDown;
            richTextBoxExtended.SelectionChanged += RichTextBoxExtended_SelectionChanged;
            richTextBoxExtended.LoadFile(filename, RichTextBoxStreamType.PlainText);

            richTextBoxExtended.strFilename = filename;

            richTextBoxExtended.Dock = DockStyle.Fill;

            richTextBoxExtended.Multiline = true;

            richTextBoxExtended.WordWrap = false;

            tp.Controls.Add(richTextBoxExtended);

            return;
        }
        //else if (e.KeyCode == Keys.F3)
        //{
        //    MessageBox.Show("11");

        //    //if (oldtabpage != null)
        //    //    this.tabControlCenter.SelectedTab = oldtabpage;

        //    return;
        //}

        //因为以后不光是文本朗读 网页也有可能朗读 所以还是放到main里面
        //        else if (e.KeyCode == Keys.F4)
        //        {
        //            if (tabControlCenter.SelectedTab != null) {
        //                if (tabControlCenter.SelectedTab.Controls.Count > 0) {
        //}
        //            }

        //            function.read.readtxt();
        //            return;
        //        }
    }

    //protected override bool ProcessDialogKey(Keys keyData)
    //{
    //    return base.ProcessDialogKey(keyData);
    //}
    private void tabControlCenter_Selected_1(object sender, TabControlEventArgs e)
    {
        //history_add(this.tabControlCenter.SelectedTab);
    }

    //private void textBoxSearch_TextChanged(object sender, EventArgs e)
    //{
    //    ////MessageBox.Show("1");
    //    //this.lst_search.Items.Add("1");
    //    //this.lst_search.ItemHeight = 12;
    //    //this.lst_search.Location = new System.Drawing.Point(textBoxSearch.Left, textBoxSearch.Bottom);
    //    //this.lst_search.Name = "lst_search";
    //    //this.lst_search.Size = new System.Drawing.Size(272, 172);
    //    //this.panel_tabpage.Controls.Add(lst_search);
    //    //this.lst_search.Visible=true;

    //}

    private void comboBoxSearch_TextChanged(object sender, EventArgs e)
    {
        //search_get();
        //Thread myThread = new Thread(new ThreadStart(search_get));
        //myThread.Start();
    }

    //private delegate void SetText();
    //SetText st = new SetText(this.search_get);

    /// <summary>
    /// 搜索提示
    /// </summary>
    private void search_get()
    {
        try
        {
            //comboBoxSearch.Items.Clear();
            //string s = textBoxSearch.Text;
            ////comboBoxSearch.Items.Add(s);
            //if (s.Trim() != "")
            //{
            //    string sql1 = "SELECT * FROM search where word like'%" + s + "%'";
            //    DataTable dt = SqliteHelper.GetDataTable(sql1);
            //    foreach (DataRow dr in dt.Rows)
            //    {
            //        comboBoxSearch.Items.Add(dr[0].ToString());
            //    }
            //    //comboBoxSearch.SelectionStart = s.Length;

            //    //comboBoxSearch.DroppedDown = true;
            //    //textBoxSearch.Focus();
            //}
            ////comboBoxSearch.Text = s;
        }
        catch (Exception ee) { }
    }

    private void comboBoxSearch_Click(object sender, EventArgs e)
    {
        search_get();
    }

    private void button_refresh_Click(object sender, EventArgs e)
    {
        try
        {
            this.initRootNode();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }

    /// <summary>
    /// 归并
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void button_guibing_Click(object sender, EventArgs e)
    {
        if (this.mytreeView.SelectedNode == null) { return; }
        //得到目录 判断下面的txt文件 取文件名的前10位 如果相同那么 文件名相加 内容相加 重新生成文件，删除原来的文件

        //flag
        string s = "";
        ArrayList l = new ArrayList();
        string newname = "";
        StringBuilder newcontent = new StringBuilder();
        System.Collections.Generic.List<string> guibing_ls = new System.Collections.Generic.List<string>();
        //do
        if (((ArrayList)(this.mytreeView.SelectedNode.Tag))[1].ToString() == "d")
        {
            string dir = ((ArrayList)(this.mytreeView.SelectedNode.Tag))[0].ToString();
            System.IO.DirectoryInfo dirinfo = new DirectoryInfo(dir);
            foreach (var item in dirinfo.GetFiles("*.txt"))
            {
                string strdate = item.Name.Substring(0, 10);

                //ru guo xiang deng fang dao shu zu
                if (strdate == s)
                {
                    newname = strdate;
                    l.Add(item);
                }
                //ru guo bu deng he bing shu zu ,qing chu shu zu,flag chong xin fu zhi
                else
                {
                    if (l.Count > 1)
                    {
                        guibing_file(ref s, l, ref newname, newcontent, guibing_ls, dirinfo);
                    }

                    l.Clear();
                    s = "";
                    l.Add(item);
                    s = item.Name.Substring(0, 10);
                }
            }

            if (l.Count > 1)
            {
                guibing_file(ref s, l, ref newname, newcontent, guibing_ls, dirinfo);
            }
        }

        file_del(guibing_ls);
        LoadDirAndFile(mytreeView.SelectedNode);
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="s"></param>
    /// <param name="l"></param>
    /// <param name="newname"></param>
    /// <param name="newcontent"></param>
    /// <param name="guibing_ls"></param>
    /// <param name="dirinfo"></param>
    private static void guibing_file(ref string s, ArrayList l, ref string newname, StringBuilder newcontent, System.Collections.Generic.List<string> guibing_ls, System.IO.DirectoryInfo dirinfo)
    {
        foreach (var itemfile in l)
        {
            //string namefull=((System.IO.FileInfo)itemfile).FullName;
            guibing_ls.Add(((System.IO.FileInfo)itemfile).FullName);
            string name = Path.GetFileNameWithoutExtension(((System.IO.FileInfo)itemfile).FullName);
            string name1 = name.Substring(10, name.Length - 10);
            newname += name1;

            StreamReader sr = new StreamReader(((System.IO.FileInfo)itemfile).FullName, Encoding.Default);
            newcontent.Append(sr.ReadToEnd());
            sr.Close();
            newcontent.Append("\r\n");
            newcontent.Append("\r\n");
        }
        newname += ".txt";
        System.IO.StreamWriter sw = new StreamWriter(Path.Combine(dirinfo.FullName, newname), false, Encoding.Default);
        sw.Write(newcontent.ToString());
        sw.Close();

        newname = "";
        //newcontent.Clear();
        l.Clear();
        s = "";
    }

    /// <summary>
    /// 归并 del
    /// </summary>
    /// <param name="l"></param>
    public void file_del(System.Collections.Generic.List<string> l)
    {
        foreach (var itemfile in l)
        {
            FileCtrl.PutRececal(itemfile);
        }
    }

    /// <summary>
    /// 展开全部
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void button1_Click(object sender, EventArgs e)
    {
        LoadDirAndFileAll(this.mytreeView.SelectedNode);
    }

    /// <summary>
    /// 收起全部
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void button2_Click(object sender, EventArgs e)
    {
        mytreeView.SelectedNode.Collapse();
    }

    private void panel_top_Paint(object sender, PaintEventArgs e)
    {
    }

    private void button_gundong_Click(object sender, EventArgs e)
    {
        guandong();
    }

    private void guandong()
    {
        try
        {
            //if (this.comboBox_search.Text == "文字")
            if (this.radioButton3.Checked)
            {
                var tb = this.tabControlCenter.SelectedTab;
                if (tb.Controls.Count > 0)
                {
                    //是文字
                    if (tb.Controls[0].Tag == null)
                    {
                        (tb.Controls[0] as MyRichTextBox).ScrollPosition();
                    }
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }

    private void tabPage1_Click(object sender, EventArgs e)
    {
    }

    #region button event

    /// <summary>
    /// 随机
    /// 如果选中的是文本 直接去文本的随机文字
    /// 如果是文件夹 先随机到下面的文件 随机多少层有疑问
    /// 所以文件夹 随机到下面的文件夹
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void button_suiji_Click(object sender, EventArgs e)
    {
        //选中文本

        if (this.tabControlCenter.SelectedTab != null)
        {
            var tb1 = this.tabControlCenter.SelectedTab;
            if ((tb1.Tag as common.TabPageTag).type == "textbox")
            {
                var a = tb1.Controls[0] as MyRichTextBox;
                int i = a.Text.Length;
                int len = 300;
                Random r = new Random();
                if (i - 300 >= 0)
                {
                    int start = r.Next(1, i - len);
                    a.Select(start, len);
                    a.SelectionColor = Color.Red;
                    a.ScrollToCaret();
                }
            }
        }
    }

    /// <summary>
    /// 添加月份
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    ///
    private void button_temp_Click(object sender, EventArgs e)
    {
        //if (this.treeViewDirect.SelectedNode == null) { return; }
        ////得到目录 判断下面的txt文件 取文件名的前10位 如果相同那么 文件名相加 内容相加 重新生成文件，删除原来的文件

        ////flag
        ////string s = "";
        ////ArrayList l = new ArrayList();
        //string newname = "";
        ////StringBuilder newcontent = new StringBuilder();
        //System.Collections.Generic.List<string> guibing_ls = new System.Collections.Generic.List<string>();
        ////do
        //if (((ArrayList)(this.treeViewDirect.SelectedNode.Tag))[1].ToString() == "d")
        //{
        //    string dir = ((ArrayList)(this.treeViewDirect.SelectedNode.Tag))[0].ToString();
        //    System.IO.DirectoryInfo dirinfo = new DirectoryInfo(dir);

        //    newname = Path.Combine(dirinfo.FullName, dirinfo.Name + ".txt");
        //    //File

        //    StringBuilder sb = new StringBuilder();

        //    foreach (var item in dirinfo.GetFileSystemInfos())
        //    {
        //        //guibing_ls.Add(item.FullName);
        //        sb.Append(item.Name);
        //        sb.Append("\r\n");
        //        //StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
        //        //string temp = sr.ReadToEnd();
        //        //sr.Close();
        //        //sb.Append(temp);
        //        sb.Append("\r\n");
        //        sb.Append("\r\n");
        //    }

        //    StreamWriter sw = new StreamWriter(newname, false, Encoding.Default);
        //    sw.Write(sb.ToString());
        //    sw.Flush();
        //    sw.Close();
        //    sb.Clear();
        //}

        ////file_del(guibing_ls);
        //LoadDirAndFile(treeViewDirect.SelectedNode);

        ///补充每年的目录 取所有目录名如果有在1-12中的就把1-12中数字删除掉
        ///然后没有删除掉数字建目录 刷新node
        ArrayList a = new ArrayList();
        a.Add("1");
        a.Add("2");
        a.Add("3");
        a.Add("4");
        a.Add("5");
        a.Add("6");
        a.Add("7");
        a.Add("8");
        a.Add("9");
        a.Add("910");
        a.Add("911");
        a.Add("912");
        foreach (TreeNode item in mytreeView.SelectedNode.Nodes)
        {
            if ((item.Tag as ArrayList)[1].ToString() == "d")
            {
                foreach (var item1 in a)
                {
                    if (item.Name == item1.ToString())
                    {
                        a.Remove(item1);
                    }
                }
            }
        }

        foreach (var item1 in a)
        {
            string strFileName = item1.ToString();
            string strFile = Path.Combine(((ArrayList)this.mytreeView.SelectedNode.Tag)[0].ToString(), strFileName);
            if (!Directory.Exists(strFile))
            {
                Directory.CreateDirectory(strFile);
            }
        }

        LoadDirAndFile(mytreeView.SelectedNode);
    }

    /// <summary>
    /// 添加日期
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void button3_Click(object sender, EventArgs e)
    {
        ///添加文件 把日期文件补全
        ///先获取文件夹 再获取上层文件夹 去前四位如果是数字就没问题
        ///得到年份月份 得到年份月份下所由天 如果没有这天就添加文件

        string nianfen = mytreeView.SelectedNode.Parent.Text;
        //string nianfen = (treeViewDirect.SelectedNode.Parent.Tag as ArrayList)[0] as string;
        if (nianfen.Length > 4 && System.Text.RegularExpressions.Regex.IsMatch(nianfen.Substring(0, 4), "\\d"))
        {
            //System.DateTime d = new DateTime();
            //TimeSpan t = new TimeSpan();
            ///此处得到某月下所有日期没有这个函数
            ///为了简化得到其他月份30天 2月28天
            ///

            nianfen = nianfen.Substring(0, 4);
            //string yuefen = (treeViewDirect.SelectedNode.Tag as ArrayList)[0] as string;
            string yuefen = mytreeView.SelectedNode.Text;
            if (yuefen.Length < 4)
            {
                if (yuefen == "910")
                {
                    yuefen = "10";
                }
                else if (yuefen == "911")
                {
                    yuefen = "11";
                }
                else if (yuefen == "912")
                {
                    yuefen = "12";
                }

                int changdu = 0;

                List<string> sanyi = new List<string>();
                sanyi.Add("1");
                sanyi.Add("3");
                sanyi.Add("5");
                sanyi.Add("7");
                sanyi.Add("8");
                sanyi.Add("10");
                sanyi.Add("12");

                List<string> sanshi = new List<string>();
                sanshi.Add("4");
                sanshi.Add("6");
                sanshi.Add("9");
                sanshi.Add("11");

                if (sanyi.Contains(yuefen))
                {
                    changdu = 31;
                }
                else if (sanshi.Contains(yuefen))
                {
                    changdu = 30;
                }
                else
                {
                    changdu = 28;
                }

                if (yuefen.Length == 1)
                {
                    yuefen = "0" + yuefen;
                }

                ArrayList suoyouriqi = new ArrayList();
                for (int i = 0; i < changdu; i++)
                {
                    string riqi = (i + 1).ToString();
                    if ((i + 1).ToString().Length == 1)
                    {
                        riqi = "0" + (i + 1).ToString();
                    }
                    suoyouriqi.Add(nianfen + "-" + yuefen + "-" + riqi);
                }

                List<string> yiyouriqi = new List<string>();
                string path = (mytreeView.SelectedNode.Tag as ArrayList)[0] as string;
                DirectoryInfo di = new DirectoryInfo(path);
                ArrayList suoyouriqi1 = suoyouriqi.Clone() as ArrayList;
                foreach (var item in di.GetFiles())
                {
                    //string s = item.Name;
                    if (item.Name.Length > 10)
                    {
                        string s = item.Name.Substring(0, 10);
                        foreach (var item1 in suoyouriqi1)
                        {
                            if (s == item1.ToString())
                            {
                                suoyouriqi.Remove(item1);
                            }
                        }
                    }
                }

                foreach (var item in suoyouriqi)
                {
                    string file = Path.Combine(path, item + ".txt");
                    FileInfo f = new FileInfo(file);
                    FileStream fs = f.Create();
                    fs.Close();
                    //f = null;
                }

                LoadDirAndFile(mytreeView.SelectedNode);
            }
        }
    }

    /// <summary>
    /// 归纳名称
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void button5_Click(object sender, EventArgs e)
    {
        ///合并文件夹
        ///
        string newname = "";
        //StringBuilder newcontent = new StringBuilder();
        System.Collections.Generic.List<string> guibing_ls = new System.Collections.Generic.List<string>();
        //do
        if (((ArrayList)(this.mytreeView.SelectedNode.Tag))[1].ToString() == "d")
        {
            string dir = ((ArrayList)(this.mytreeView.SelectedNode.Tag))[0].ToString();
            System.IO.DirectoryInfo dirinfo = new DirectoryInfo(dir);

            newname = Path.Combine(dirinfo.FullName, dirinfo.Name + ".txt");
            //File

            StringBuilder sb = new StringBuilder();

            foreach (var item in dirinfo.GetFileSystemInfos())
            {
                //guibing_ls.Add(item.FullName);
                sb.Append(item.Name);
                sb.Append("\r\n");
                //StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
                //string temp = sr.ReadToEnd();
                //sr.Close();
                //sb.Append(temp);
                sb.Append("\r\n");
                sb.Append("\r\n");
            }

            StreamWriter sw = new StreamWriter(newname, false, Encoding.Default);
            sw.Write(sb.ToString());
            sw.Flush();
            sw.Close();
            //sb.Clear();
        }

        //file_del(guibing_ls);
        LoadDirAndFile(mytreeView.SelectedNode);
    }

    /// <summary>
    /// 合并文件
    /// 归并是把所有文件内容合并 合并是文件名和内容都写到文件里 然后文件夹名为文件名
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void button_hebing_Click(object sender, EventArgs e)
    {
        hebingwenjian();
    }

    private void hebingwenjian()
    {
        if (this.mytreeView.SelectedNode == null) { return; }

        string newname = "";
        //StringBuilder newcontent = new StringBuilder();
        System.Collections.Generic.List<string> guibing_ls = new System.Collections.Generic.List<string>();
        //do
        if (((ArrayList)(this.mytreeView.SelectedNode.Tag))[1].ToString() == "d")
        {
            string dir = ((ArrayList)(this.mytreeView.SelectedNode.Tag))[0].ToString();
            System.IO.DirectoryInfo dirinfo = new DirectoryInfo(dir);

            newname = Path.Combine(dirinfo.FullName, dirinfo.Name + ".txt");
            //File

            StringBuilder sb = new StringBuilder();

            foreach (var item in dirinfo.GetFiles("*.txt"))
            {
                guibing_ls.Add(item.FullName);
                sb.Append(item.Name);
                sb.Append("\r\n");
                StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
                string temp = sr.ReadToEnd();
                sr.Close();
                sb.Append(temp);
                sb.Append("\r\n");
                sb.Append("\r\n");

                //string strdate = item.Name.Substring(0, 10);

                //ru guo xiang deng fang dao shu zu
                //if (strdate == s)
                //{
                //    newname = strdate;
                //    l.Add(item);
                //}
                ////ru guo bu deng he bing shu zu ,qing chu shu zu,flag chong xin fu zhi
                //else
                //{
                //    if (l.Count > 1)
                //    {
                //        guibing_file(ref s, l, ref newname, newcontent, guibing_ls, dirinfo);
                //    }

                //    l.Clear();
                //    s = "";
                //    l.Add(item);
                //    s = item.Name.Substring(0, 10);
                //}
            }

            foreach (var item in dirinfo.GetFiles("*.py"))
            {
                guibing_ls.Add(item.FullName);
                sb.Append(item.Name);
                sb.Append("\r\n");
                StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
                string temp = sr.ReadToEnd();
                sr.Close();
                sb.Append(temp);
                sb.Append("\r\n");
                sb.Append("\r\n");
            }

            foreach (var item in dirinfo.GetFiles("*.cs"))
            {
                guibing_ls.Add(item.FullName);
                sb.Append(item.Name);
                sb.Append("\r\n");
                StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
                string temp = sr.ReadToEnd();
                sr.Close();
                sb.Append(temp);
                sb.Append("\r\n");
                sb.Append("\r\n");
            }

            //if (l.Count > 1)
            //{
            //    guibing_file(ref s, l, ref newname, newcontent, guibing_ls, dirinfo);
            //}
            StreamWriter sw = new StreamWriter(newname, false, Encoding.Default);
            sw.Write(sb.ToString());
            sw.Flush();
            sw.Close();
            //sb.Clear();
        }

        //解决文件和文件夹名字相同的问题
        guibing_ls.Remove(newname);

        file_del(guibing_ls);
        LoadDirAndFile(mytreeView.SelectedNode);
    }

    private void hebingwenjiandigui()
    {
        if (this.mytreeView.SelectedNode == null) { return; }

        string newname = "";
        //StringBuilder newcontent = new StringBuilder();
        //System.Collections.Generic.List<string> guibing_ls = new System.Collections.Generic.List<string>();
        //do
        if (((ArrayList)(this.mytreeView.SelectedNode.Tag))[1].ToString() == "d")
        {
            string dir = ((ArrayList)(this.mytreeView.SelectedNode.Tag))[0].ToString();
            System.IO.DirectoryInfo dirinfo = new DirectoryInfo(dir);

            newname = Path.Combine(dirinfo.FullName, dirinfo.Name + ".txt");
            //File

            StringBuilder sb = new StringBuilder();
            hebingwenjiandiguiOne(dir, sb);

            StreamWriter sw = new StreamWriter(newname, false, Encoding.Default);
            sw.Write(sb.ToString());
            sw.Flush();
            sw.Close();
        }

        //解决文件和文件夹名字相同的问题
        //guibing_ls.Remove(newname);

        //file_del(guibing_ls);
        LoadDirAndFile(mytreeView.SelectedNode);
    }

    private void kongwenjianjia()
    {
        if (this.mytreeView.SelectedNode == null) { return; }

        //string newname = "";

        if (((ArrayList)(this.mytreeView.SelectedNode.Tag))[1].ToString() == "d")
        {
            string dir = ((ArrayList)(this.mytreeView.SelectedNode.Tag))[0].ToString();
            System.IO.DirectoryInfo dirinfo = new DirectoryInfo(dir);

            //newname = Path.Combine(dirinfo.FullName, dirinfo.Name + ".txt");
            //File

            StringBuilder sb = new StringBuilder();
            kongwenjianjiaOne(dir, sb);
        }

        //解决文件和文件夹名字相同的问题
        //guibing_ls.Remove(newname);

        //file_del(guibing_ls);
        LoadDirAndFile(mytreeView.SelectedNode);
    }

    private void kongwenjianjiaOne(string path, StringBuilder sb)
    {
        DirectoryInfo dirinfo = new DirectoryInfo(path);
        DirectoryInfo[] d2 = dirinfo.GetDirectories();

        foreach (DirectoryInfo d3 in d2)
        {
            kongwenjianjiaOne(d3.FullName, sb);
        }

        FileInfo[] f2 = dirinfo.GetFiles();
        string newname = "";
        newname = Path.Combine(dirinfo.FullName, "keep" + ".txt");
        if (d2.Length == 0 && f2.Length == 0)
        {
            StreamWriter sw = new StreamWriter(newname, false, Encoding.Default);
            sw.Write(sb.ToString());
            sw.Flush();
            sw.Close();
        }
    }

    private void hebingwenjiandiguiOne(string path, StringBuilder sb)
    {
        DirectoryInfo dirinfo = new DirectoryInfo(path);
        DirectoryInfo[] d2 = dirinfo.GetDirectories();

        foreach (DirectoryInfo d3 in d2)
        {
            hebingwenjiandiguiOne(d3.FullName, sb);
        }

        sb.Append((new DirectoryInfo(path)).FullName);
        sb.Append(Environment.NewLine);

        foreach (var item in dirinfo.GetFiles("*.txt"))
        {
            sb.Append(item.Name);
            sb.Append("\r\n");
            StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
            string temp = sr.ReadToEnd();
            sr.Close();
            sb.Append(temp);
            sb.Append("\r\n");
            sb.Append("\r\n");
        }

        foreach (var item in dirinfo.GetFiles("*.bat"))
        {
            sb.Append(item.Name);
            sb.Append("\r\n");
            StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
            string temp = sr.ReadToEnd();
            sr.Close();
            sb.Append(temp);
            sb.Append("\r\n");
            sb.Append("\r\n");
        }

        foreach (var item in dirinfo.GetFiles("*.php"))
        {
            sb.Append(item.Name);
            sb.Append("\r\n");
            StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
            string temp = sr.ReadToEnd();
            sr.Close();
            sb.Append(temp);
            sb.Append("\r\n");
            sb.Append("\r\n");
        }

        foreach (var item in dirinfo.GetFiles("*.frm"))
        {
            sb.Append(item.Name);
            sb.Append("\r\n");
            StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
            string temp = sr.ReadToEnd();
            sr.Close();
            sb.Append(temp);
            sb.Append("\r\n");
            sb.Append("\r\n");
        }

        foreach (var item in dirinfo.GetFiles("*.vb"))
        {
            sb.Append(item.Name);
            sb.Append("\r\n");
            StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
            string temp = sr.ReadToEnd();
            sr.Close();
            sb.Append(temp);
            sb.Append("\r\n");
            sb.Append("\r\n");
        }

        foreach (var item in dirinfo.GetFiles("*.h"))
        {
            sb.Append(item.Name);
            sb.Append("\r\n");
            StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
            string temp = sr.ReadToEnd();
            sr.Close();
            sb.Append(temp);
            sb.Append("\r\n");
            sb.Append("\r\n");
        }

        foreach (var item in dirinfo.GetFiles("*.c"))
        {
            sb.Append(item.Name);
            sb.Append("\r\n");
            StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
            string temp = sr.ReadToEnd();
            sr.Close();
            sb.Append(temp);
            sb.Append("\r\n");
            sb.Append("\r\n");
        }

        foreach (var item in dirinfo.GetFiles("*.cpp"))
        {
            sb.Append(item.Name);
            sb.Append("\r\n");
            StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
            string temp = sr.ReadToEnd();
            sr.Close();
            sb.Append(temp);
            sb.Append("\r\n");
            sb.Append("\r\n");
        }

        foreach (var item in dirinfo.GetFiles("*.py"))
        {
            sb.Append(item.Name);
            sb.Append("\r\n");
            StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
            string temp = sr.ReadToEnd();
            sr.Close();
            sb.Append(temp);
            sb.Append("\r\n");
            sb.Append("\r\n");
        }

        foreach (var item in dirinfo.GetFiles("*.cs"))
        {
            sb.Append(item.Name);
            sb.Append("\r\n");
            StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
            string temp = sr.ReadToEnd();
            sr.Close();
            sb.Append(temp);
            sb.Append("\r\n");
            sb.Append("\r\n");
        }

        foreach (var item in dirinfo.GetFiles("*.aspx"))
        {
            sb.Append(item.Name);
            sb.Append("\r\n");
            StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
            string temp = sr.ReadToEnd();
            sr.Close();
            sb.Append(temp);
            sb.Append("\r\n");
            sb.Append("\r\n");
        }

        foreach (var item in dirinfo.GetFiles("*.java"))
        {
            sb.Append(item.Name);
            sb.Append("\r\n");
            StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
            string temp = sr.ReadToEnd();
            sr.Close();
            sb.Append(temp);
            sb.Append("\r\n");
            sb.Append("\r\n");
        }

        foreach (var item in dirinfo.GetFiles("*.htm"))
        {
            sb.Append(item.Name);
            sb.Append("\r\n");
            StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
            string temp = sr.ReadToEnd();
            sr.Close();
            sb.Append(temp);
            sb.Append("\r\n");
            sb.Append("\r\n");
        }

        foreach (var item in dirinfo.GetFiles("*.html"))
        {
            sb.Append(item.Name);
            sb.Append("\r\n");
            StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
            string temp = sr.ReadToEnd();
            sr.Close();
            sb.Append(temp);
            sb.Append("\r\n");
            sb.Append("\r\n");
        }

        foreach (var item in dirinfo.GetFiles("*.js"))
        {
            sb.Append(item.Name);
            sb.Append("\r\n");
            StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
            string temp = sr.ReadToEnd();
            sr.Close();
            sb.Append(temp);
            sb.Append("\r\n");
            sb.Append("\r\n");
        }

        foreach (var item in dirinfo.GetFiles("*.sql"))
        {
            sb.Append(item.Name);
            sb.Append("\r\n");
            StreamReader sr = new StreamReader(item.FullName, Encoding.Default);
            string temp = sr.ReadToEnd();
            sr.Close();
            sb.Append(temp);
            sb.Append("\r\n");
            sb.Append("\r\n");
        }
    }

    /// <summary>
    /// 去空行
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void qukonghang1(object sender, EventArgs e)
    {
        //1duqu
        //string sPath = TreeViewHelper.GetPath(treeViewDirect.SelectedNode);
        //StreamReader sr = new StreamReader(sPath,Encoding.Default);
        StringBuilder tempStr = new StringBuilder();

        var tb1 = this.tabControlCenter.SelectedTab;
        if (tb1.Controls.Count > 0)
        {
            if (tb1.Controls[0].Tag == null)
            {
                //tempStr.Append((tb1.Controls[0] as MyRichTextBox).Text);
                var lines = (tb1.Controls[0] as MyRichTextBox).Text.Split(new string[] { "\n" }, StringSplitOptions.None);
                foreach (var s in lines)
                {
                    if (!string.IsNullOrEmpty(s))
                    {
                        tempStr.AppendLine(s);
                    }
                }
            }
        }

        ///2xiugai
        ///
        //while( !sr.EndOfStream){
        //     string s=sr.ReadLine();

        //     if (!string.IsNullOrEmpty(s)) {
        //         tempStr.AppendLine( s);
        //     }
        //}
        //sr.Close();
        //tempStr.fi

        //3xianshi
        var tb = this.tabControlCenter.SelectedTab;
        if (tb.Controls.Count > 0)
        {
            if (tb.Controls[0].Tag == null)
            {
                (tb.Controls[0] as MyRichTextBox).Text = tempStr.ToString();
            }
        }

        ///4chucun
        ///
        //string tempStr = File.ReadAllText(sPath, Encoding.Default);//读取文档
        //tempStr = Regex.Replace(tempStr, @"(\s)+", "\r\n\r\n");//替换为两个个换行,可以自己输入……
        //StreamWriter sw = new StreamWriter(sPath, false, Encoding.Default);
        //sw.Write(tempStr.ToString());
        //sw.Close();
    }

    /// <summary>
    /// 去除所有空行
    /// </summary>
    private void qukonghang()
    {
        StringBuilder tempStr = new StringBuilder();
        var tb1 = this.tabControlCenter.SelectedTab;
        if (tb1 != null && tb1.Controls.Count > 0)
        {
            if (tb1.Controls[0].Tag == null)
            {
                var control = (tb1.Controls[0] as MyRichTextBox);
                if (!string.IsNullOrEmpty(control.SelectedText))
                {
                    var lines = control.SelectedText.Split(new string[] { "\n" }, StringSplitOptions.None);
                    foreach (var s in lines)
                    {
                        if (!string.IsNullOrEmpty(s))
                        {
                            tempStr.AppendLine(s);
                        }
                    }

                    //control.SelectedText.Replace(control.SelectedText,tempStr.ToString());
                    control.SelectedText = tempStr.ToString();
                }
            }
        }
    }

    private static string CapText(Match m)
    {
        try
        {
            DateTime d1 = Convert.ToDateTime(m.Value);
            var strTime = d1.ToString("yyyy年M月d日");
            return strTime;
        }
        catch (Exception)
        {
            return m.Value;
        }
    }

    private void geshihuariqi()
    {
        //int count = 0;
        StringBuilder tempStr = new StringBuilder();
        var tb1 = this.tabControlCenter.SelectedTab;
        if (tb1 != null && tb1.Controls.Count > 0)
        {
            if (tb1.Controls[0].Tag == null)
            {
                var control = (tb1.Controls[0] as MyRichTextBox);
                if (!string.IsNullOrEmpty(control.Text))
                {
                    //var lines = control.SelectedText.Split(new string[] { "\n" }, StringSplitOptions.None);
                    var lines = control.Text.Split(new string[] { "\n" }, StringSplitOptions.None);
                    foreach (var s in lines)
                    {
                        string result = Regex.Replace(s, @"((\d{4}|\d{2})(\-|\/|\.)\d{1,2}\3\d{1,2})",
        new MatchEvaluator(CapText));
                        tempStr.AppendLine(result);
                    }

                    //control.SelectedText.Replace(control.SelectedText,tempStr.ToString());
                    control.Text = tempStr.ToString();
                }
            }
        }
    }

    private void danyikonghang()
    {
        int count = 0;
        StringBuilder tempStr = new StringBuilder();
        var tb1 = this.tabControlCenter.SelectedTab;
        if (tb1 != null && tb1.Controls.Count > 0)
        {
            if (tb1.Controls[0].Tag == null)
            {
                var control = (tb1.Controls[0] as MyRichTextBox);
                if (!string.IsNullOrEmpty(control.Text))
                {
                    //var lines = control.SelectedText.Split(new string[] { "\n" }, StringSplitOptions.None);
                    var lines = control.Text.Split(new string[] { "\n" }, StringSplitOptions.None);
                    foreach (var s in lines)
                    {
                        if (!string.IsNullOrEmpty(s.Trim()))
                        {
                            if (count == 0)
                            {
                                tempStr.AppendLine(s);
                            }
                            else
                            {
                                tempStr.AppendLine("");
                                tempStr.AppendLine(s);
                                count = 0;
                            }
                        }
                        else
                        {
                            count++;
                        }
                    }

                    //control.SelectedText.Replace(control.SelectedText,tempStr.ToString());
                    control.Text = tempStr.ToString();
                }
            }
        }
    }

    private void quchongfu()
    {
        int count = 0;
        StringBuilder tempStr = new StringBuilder();
        var tb1 = this.tabControlCenter.SelectedTab;
        if (tb1 != null && tb1.Controls.Count > 0)
        {
            if (tb1.Controls[0].Tag == null)
            {
                var control = (tb1.Controls[0] as MyRichTextBox);
                if (!string.IsNullOrEmpty(control.Text))
                {
                    //var lines = control.SelectedText.Split(new string[] { "\n" }, StringSplitOptions.None);
                    var lines = control.Text.Split(new string[] { "\n" }, StringSplitOptions.None);
                    List<string> vs = new List<string>();
                    foreach (var s in lines)
                    {
                        if (!vs.Contains(s))
                        {
                            vs.Add(s);
                        }
                        //if (!string.IsNullOrEmpty(s.Trim()))
                        //{
                        //    if (count == 0)
                        //    {
                        //        tempStr.AppendLine(s);
                        //    }
                        //    else
                        //    {
                        //        tempStr.AppendLine("");
                        //        tempStr.AppendLine(s);
                        //        count = 0;
                        //    }
                        //}
                        //else
                        //{
                        //    count++;
                        //}
                    }
                    foreach (var s in vs)
                    {
                        tempStr.AppendLine(s);
                    }
                    //control.SelectedText.Replace(control.SelectedText,tempStr.ToString());
                    control.Text = tempStr.ToString();
                }
            }
        }
    }

    #endregion

    private void button_do(object sender, EventArgs e)
    {
        dofunction();
    }

    private bool readflag;
    private TabPage currenttabpage;
    private TabPage oldtabpage;

    private void dofunction()
    {
        string word = this.textBoxdofunction.Text;

        //只显示一个
        foreach (TabPage tpTemp in tabControlCenter.Controls)
        {
            if (tpTemp.Tag != null && tpTemp.Tag.ToString() == word)
            {
                this.tabControlCenter.SelectedTab = tpTemp;
                return;
            }
        }
        if (word == "read")
        {
            //if (this.tabControlCenter.SelectedTab != null)
            //{
            //    var tb1 = this.tabControlCenter.SelectedTab;
            //    if (tb1.Controls.Count > 0)
            //    {
            //        if (tb1.Controls[0].Tag == null)
            //        {
            //            var a = tb1.Controls[0] as MyRichTextBox;

            //            if (string.IsNullOrEmpty(a.SelectedText))
            //            {
            //                int i = a.Text.Length;
            //                int len = 1000;
            //                Random r = new Random();
            //                if (i - 1000 >= 0)
            //                {
            //                    int start = r.Next(1, i - len);
            //                    a.Select(start, len);
            //                    a.SelectionColor = Color.Red;
            //                    a.ScrollToCaret();
            //                }
            //            }

            //            UserControlread userControlpiano = new UserControlread(a.SelectedText);
            //            Panel panel = new Panel();

            //            panel.Tag = "read";
            //            panel.AutoScroll = true;
            //            panel.Dock = DockStyle.Fill;
            //            panel.Controls.Add(userControlpiano);

            //            TabPage tp = new TabPage();
            //            tp.Text = "read";
            //            tp.Tag = "read";
            //            this.tabControlCenter.SelectedTab = tp;
            //            this.tabControlCenter.Controls.Add(tp);

            //            //tp.Controls.Add(webBrowser1);
            //            tp.Controls.Add(panel);
            //            tp.AutoScroll = true;

            //            userControlpiano.Focus();

            //            //ee += new aa(userControlpiano.Stop);
            //        }
            //    }
            //}

            UserControlread userControlpiano = new UserControlread();
            Panel panel = new Panel();

            panel.Tag = "read";
            panel.AutoScroll = true;
            panel.Dock = DockStyle.Fill;
            panel.Controls.Add(userControlpiano);

            TabPage tp = new TabPage();
            tp.Text = "read";
            tp.Tag = "read";
            this.tabControlCenter.SelectedTab = tp;
            this.tabControlCenter.Controls.Add(tp);

            //tp.Controls.Add(webBrowser1);
            tp.Controls.Add(panel);
            tp.AutoScroll = true;

            userControlpiano.Focus();
            return;
        }
        else if (word == "quchongfu") { quchongfu(); }
        else if (word == "json")
        {
            //function.jsonview.UserControl1 userControlpiano = new function.jsonview.UserControl1();
            //userControlpiano.Dock = DockStyle.Fill;
            //Panel panel = new Panel();

            //panel.AutoScroll = true;
            //panel.Dock = DockStyle.Fill;
            //panel.Controls.Add(userControlpiano);

            //TabPage tp = new TabPage();
            //tp.Text = "json";
            //tp.Tag = "json";
            //this.tabControlCenter.SelectedTab = tp;
            //this.tabControlCenter.Controls.Add(tp);

            //tp.Controls.Add(panel);
            //tp.AutoScroll = true;

            //userControlpiano.Focus();
            try
            {
                Process.Start(strGreen + "\\JsonView\\JsonView.exe");
            }
            catch (Exception)
            {
            }

            return;
        }
        else if (word == "snake")
        {
            game.snake.UserControlsnake userControlpiano = new game.snake.UserControlsnake();
            userControlpiano.Dock = DockStyle.Fill;
            Panel panel = new Panel();

            panel.AutoScroll = true;
            panel.Dock = DockStyle.Fill;
            panel.Controls.Add(userControlpiano);

            TabPage tp = new TabPage();
            tp.Text = "snake";
            tp.Tag = "snake";
            this.tabControlCenter.SelectedTab = tp;
            this.tabControlCenter.Controls.Add(tp);

            tp.Controls.Add(panel);
            tp.AutoScroll = true;

            userControlpiano.Focus();

            return;
        }
        else if (word == "server")
        {
            string dirname = data.xml.xml_help.get_server();
            //string name = Path.GetFileName(dirname);

            UserControlhttp userControlpiano = new UserControlhttp(dirname);
            Panel panel = new Panel();

            //panel.Tag = "paint";
            panel.AutoScroll = true;
            panel.Dock = DockStyle.Fill;
            panel.Controls.Add(userControlpiano);

            TabPage tp = new TabPage();
            tp.Text = "server";
            tp.Tag = "server";
            this.tabControlCenter.SelectedTab = tp;
            this.tabControlCenter.Controls.Add(tp);

            tp.Controls.Add(panel);
            tp.AutoScroll = true;

            userControlpiano.Focus();

            return;
        }
        //else if (word == "pintu")
        //{
        //    if (this.tabControlCenter.SelectedTab != null)
        //    {
        //        var tb1 = this.tabControlCenter.SelectedTab;
        //        if (tb1.Controls.Count > 0)
        //        {
        //            if (tb1.Controls[0].Tag != null && tb1.Controls[0].Tag.ToString() == "img")
        //            {
        //                UserControlpintu userControlpiano = new UserControlpintu(tb1.Tag.ToString());
        //                Panel panel = new Panel();

        //                panel.Tag = "pintu";
        //                panel.AutoScroll = true;
        //                panel.Dock = DockStyle.Fill;
        //                panel.Controls.Add(userControlpiano);

        //                TabPage tp = new TabPage();
        //                tp.Text = "pintu";
        //                tp.Tag = "pintu";
        //                this.tabControlCenter.SelectedTab = tp;
        //                this.tabControlCenter.Controls.Add(tp);

        //                //tp.Controls.Add(webBrowser1);
        //                tp.Controls.Add(panel);
        //                tp.AutoScroll = true;

        //                userControlpiano.Focus();
        //            }
        //            else
        //            {
        //                UserControlpintu userControlpiano = new UserControlpintu();
        //                Panel panel = new Panel();

        //                //panel.Tag = "pintu";
        //                panel.AutoScroll = true;
        //                panel.Dock = DockStyle.Fill;
        //                panel.Controls.Add(userControlpiano);

        //                TabPage tp = new TabPage();
        //                tp.Text = "pintu";
        //                tp.Tag = "pintu";
        //                this.tabControlCenter.SelectedTab = tp;
        //                this.tabControlCenter.Controls.Add(tp);

        //                //tp.Controls.Add(webBrowser1);
        //                tp.Controls.Add(panel);
        //                tp.AutoScroll = true;

        //                userControlpiano.Focus();
        //            }
        //        }
        //    }
        //    else
        //    {
        //        UserControlpintu userControlpiano = new UserControlpintu();
        //        Panel panel = new Panel();

        //        //panel.Tag = "pintu";
        //        panel.AutoScroll = true;
        //        panel.Dock = DockStyle.Fill;
        //        panel.Controls.Add(userControlpiano);

        //        TabPage tp = new TabPage();
        //        tp.Text = "pintu";
        //        //tp.Tag = "cut";
        //        this.tabControlCenter.SelectedTab = tp;
        //        this.tabControlCenter.Controls.Add(tp);

        //        //tp.Controls.Add(webBrowser1);
        //        tp.Controls.Add(panel);
        //        tp.AutoScroll = true;

        //        userControlpiano.Focus();
        //    }

        //    return;
        //}
        else if (word == "tank")
        {
            //UserControltank userControltank = new UserControltank();
            //webBrowser1.Url = new Uri(url.Trim());
            //userControltank.Dock = DockStyle.Fill;

            Panel panel = new Panel();

            panel.Tag = "game";
            panel.AutoScroll = true;
            panel.Dock = DockStyle.Fill;
            //panel.Controls.Add(userControltank);

            TabPage tp = new TabPage();
            tp.Text = "tank";
            tp.Tag = "tank";
            this.tabControlCenter.SelectedTab = tp;
            this.tabControlCenter.Controls.Add(tp);

            //tp.Controls.Add(webBrowser1);
            tp.Controls.Add(panel);
            tp.AutoScroll = true;

            return;
        }
        else if (word == "random")
        {
            button_suiji_Click(null, null);

            return;
        }
        else if (word == "piano")
        {
            UserControlpiano userControlpiano = new UserControlpiano();
            userControlpiano.Dock = DockStyle.Fill;

            Panel panel = new Panel();

            panel.Tag = "game";
            panel.AutoScroll = true;
            panel.Dock = DockStyle.Fill;
            panel.Controls.Add(userControlpiano);

            TabPage tp = new TabPage();
            tp.Text = "piano";
            tp.Tag = "piano";
            this.tabControlCenter.SelectedTab = tp;
            this.tabControlCenter.Controls.Add(tp);

            //tp.Controls.Add(webBrowser1);
            tp.Controls.Add(panel);
            tp.AutoScroll = true;

            userControlpiano.Focus();

            return;
        }
        else if (word == "paint")
        {
            UserControlpaint userControlpiano = new UserControlpaint();
            //userControlpiano.Dock = DockStyle.Fill;

            Panel panel = new Panel();

            panel.Tag = "paint";
            panel.AutoScroll = true;
            panel.Dock = DockStyle.Fill;
            panel.Controls.Add(userControlpiano);

            TabPage tp = new TabPage();
            tp.Text = "paint";
            tp.Tag = "paint";
            this.tabControlCenter.SelectedTab = tp;
            this.tabControlCenter.Controls.Add(tp);

            //tp.Controls.Add(webBrowser1);
            tp.Controls.Add(panel);
            tp.AutoScroll = true;

            userControlpiano.Focus();

            return;
        }
        else if (word == "cut")
        {
            if (this.tabControlCenter.SelectedTab != null)
            {
                var tb1 = this.tabControlCenter.SelectedTab;
                if (tb1.Controls.Count > 0)
                {
                    if (tb1.Controls[0].Tag.ToString() == "img")
                    {
                        UserControlcut userControlpiano = new UserControlcut(tb1.Tag.ToString());
                        //userControlpiano.img_fullname = tb1.Tag.ToString();
                        //userControlpiano.Dock = DockStyle.Fill;

                        Panel panel = new Panel();

                        panel.Tag = "cut";
                        panel.AutoScroll = true;
                        panel.Dock = DockStyle.Fill;
                        panel.Controls.Add(userControlpiano);

                        TabPage tp = new TabPage();
                        tp.Text = "cut";
                        tp.Tag = "cut";
                        this.tabControlCenter.SelectedTab = tp;
                        this.tabControlCenter.Controls.Add(tp);

                        //tp.Controls.Add(webBrowser1);
                        tp.Controls.Add(panel);
                        tp.AutoScroll = true;

                        userControlpiano.Focus();
                    }
                }
            }

            return;
        }
        else if (word == "spirit")
        {
            //function.jsonview.UserControl1 userControlpiano = new function.jsonview.UserControl1();
            //userControlpiano.Dock = DockStyle.Fill;
            //Panel panel = new Panel();

            //panel.AutoScroll = true;
            //panel.Dock = DockStyle.Fill;
            //panel.Controls.Add(userControlpiano);

            //TabPage tp = new TabPage();
            //tp.Text = "spirit";
            //tp.Tag = "spirit";
            //this.tabControlCenter.SelectedTab = tp;
            //this.tabControlCenter.Controls.Add(tp);

            //tp.Controls.Add(panel);
            //tp.AutoScroll = true;

            //userControlpiano.Focus();

            //UserControl u = new UserControl();
            //u.Dock = DockStyle.Fill;
            ////this.tabControlCenter.Controls.Add(u);
            //u.BringToFront();

            game.spirit.UserControlspirit userControlpiano = new game.spirit.UserControlspirit();
            userControlpiano.Dock = DockStyle.Fill;

            TabPage tp = new TabPage();
            tp.Text = "spirit";
            tp.Tag = "spirit";
            this.tabControlCenter.SelectedTab = tp;
            this.tabControlCenter.Controls.Add(tp);

            tp.Controls.Add(userControlpiano);
            tp.AutoScroll = true;

            return;
        }
        else if (word == "hebingwenjian")
        {
            hebingwenjian();

            return;
        }
        else if (word == "hebingwenjiandigui")
        {
            hebingwenjiandigui();

            return;
        }
        else if (word == "kongwenjianjia")
        {
            kongwenjianjia();

            return;
        }
        else if (word == "shengchengwenjian")
        {
            shengchengwenjian();

            return;
        }
        else if (word == "mantianxing")
        {
            game.mantianxing.UserControl1 userControlpiano = new game.mantianxing.UserControl1();
            userControlpiano.Dock = DockStyle.Fill;

            TabPage tp = new TabPage();
            tp.Text = "mantianxing";
            tp.Tag = "mantianxing";
            this.tabControlCenter.SelectedTab = tp;
            this.tabControlCenter.Controls.Add(tp);

            tp.Controls.Add(userControlpiano);
            tp.AutoScroll = true;

            return;
        }
        else if (word == "guanji")
        {
            try
            {
                Process.Start(strGreen + "\\mysoft\\guanji\\guanji.exe");
            }
            catch (Exception)
            {
            }
            return;
        }
        else if (word == "jisuanqi")
        {
            function.jisuanqi.UserControl1 userControlpiano = new function.jisuanqi.UserControl1();
            userControlpiano.Dock = DockStyle.Fill;

            TabPage tp = new TabPage();
            tp.Text = "jisuanqi";
            tp.Tag = "jisuanqi";
            this.tabControlCenter.SelectedTab = tp;
            this.tabControlCenter.Controls.Add(tp);

            tp.Controls.Add(userControlpiano);
            tp.AutoScroll = true;

            return;
        }
        else if (word == "db")
        {
            try
            {
                Process.Start(strGreen + "\\mysoft\\db\\WindowsFormsApplication1.exe");
            }
            catch (Exception)
            {
            }

            return;
        }
        else if (word == "qukonghang")
        {
            qukonghang();

            return;
        }
        else if (word == "time")
        {
            if (this.tabControlCenter.SelectedTab != null)
            {
                var tb1 = this.tabControlCenter.SelectedTab;

                if (tb1.Tag is TabPageTag && (tb1.Tag as TabPageTag).type == "textbox")
                {
                    foreach (TabPage tpTemp in tabControlCenter.Controls)
                    {
                        if (tpTemp.Tag != null && tpTemp.Tag is common.TabPageTag && (tpTemp.Tag as common.TabPageTag).filename.ToString() == "time" + tb1.Text.ToString())
                        {
                            this.tabControlCenter.SelectedTab = tpTemp;
                            return;
                        }
                        else if (tb1.Text.ToString().IndexOf("time") != -1)
                        {
                            //MessageBox.Show(tb1.Tag.ToString());
                            return;
                        }
                    }

                    //var a = tb1.Controls[0] as MyRichTextBox;

                    //换另一种展示形式
                    controls.TextEditor.UserControl1 userControl1 = new controls.TextEditor.UserControl1((tb1.Tag as TabPageTag).filename);

                    userControl1.Dock = DockStyle.Fill;

                    TabPage tp = new TabPage();
                    tp.Text = "time" + tb1.Text.ToString();
                    //tp.Tag = "time" + tb1.Text.ToString();

                    TabPageTag tabPageTag = new TabPageTag();
                    tabPageTag.type = "timetextbox";
                    tabPageTag.filename = "time" + tb1.Text.ToString();

                    //tp.Tag = ((ArrayList)treeNode.Tag)[0].ToString();
                    tp.Tag = tabPageTag;

                    this.tabControlCenter.SelectedTab = tp;
                    this.tabControlCenter.Controls.Add(tp);

                    //tp.Controls.Add(webBrowser1);
                    tp.Controls.Add(userControl1);
                    tp.AutoScroll = true;

                    userControl1.Focus();
                }
            }

            return;
        }
        else if (word == "@@")
        {
            if (this.tabControlCenter.SelectedTab != null)
            {
                var tb1 = this.tabControlCenter.SelectedTab;
                if (tb1.Controls.Count > 0)
                {
                    if (tb1.Controls[0].Tag == null)
                    {
                        //Thread threadMy = new Thread(delegate() {
                        //换另一种展示形式
                        controls.TextEditor.UserControl1 userControlpiano = new controls.TextEditor.UserControl1(tb1.Tag.ToString(), "@@");
                        userControlpiano.Dock = DockStyle.Fill;

                        TabPage tp = new TabPage();
                        tp.Text = "@@";
                        tp.Tag = "@@";
                        this.tabControlCenter.SelectedTab = tp;
                        this.tabControlCenter.Controls.Add(tp);

                        //tp.Controls.Add(webBrowser1);
                        tp.Controls.Add(userControlpiano);
                        tp.AutoScroll = true;

                        userControlpiano.Focus();
                        //});
                        //threadMy.Start();
                    }
                }
            }

            return;
        }
        else if (word == "danyikonghang")
        {
            danyikonghang();

            return;
        }
        else if (word == "geshihuariqi")
        {
            geshihuariqi();

            return;
        }
        else if (word == "geshihuariqi2")
        {
            geshihuariqi2();

            return;
        }
        else if (word == "geshihuariqi3")
        {
            geshihuariqi3();

            return;
        }
        else if (word == "quxiaosvn")
        {
            quxiaosvn();

            return;
        }
    }

    private void shengchengwenjian()
    {
        if (this.mytreeView.SelectedNode == null) { return; }

        if (((ArrayList)(this.mytreeView.SelectedNode.Tag))[1].ToString() == "d")
        {
            string dir = ((ArrayList)(this.mytreeView.SelectedNode.Tag))[0].ToString();
            shengchengwenjianOne(dir);
            LoadDirAndFile(mytreeView.SelectedNode);
        }
    }

    private void shengchengwenjianOne(string dir)
    {
        //DirectoryInfo d1 = new DirectoryInfo(dir);
        if (!Directory.Exists(Path.Combine(dir, "0test")))
        {
            Directory.CreateDirectory(Path.Combine(dir, "0test"));
        }
        if (!Directory.Exists(Path.Combine(dir, "extend")))
        {
            Directory.CreateDirectory(Path.Combine(dir, "extend"));
        }
        if (!Directory.Exists(Path.Combine(dir, "base")))
        {
            Directory.CreateDirectory(Path.Combine(dir, "base"));
        }
        //if (!File.Exists(Path.Combine(dir + @"/base/", "base.txt")))
        //{
        //    File.Create(Path.Combine(dir + @"/base/", "base.txt")).Close();
        //}
        if (!File.Exists(Path.Combine(dir + @"/base/", "hello.txt")))
        {
            File.Create(Path.Combine(dir + @"/base/", "hello.txt")).Close();
        }
    }

    private void quxiaosvn()
    {
        if (this.mytreeView.SelectedNode == null) { return; }

        if (((ArrayList)(this.mytreeView.SelectedNode.Tag))[1].ToString() == "d")
        {
            string dir = ((ArrayList)(this.mytreeView.SelectedNode.Tag))[0].ToString();
            DeleteSvn(dir);
        }
    }

    private void DeleteSvn(string path)
    {
        DirectoryInfo d1 = new DirectoryInfo(path);
        DirectoryInfo[] d2 = d1.GetDirectories();

        foreach (DirectoryInfo d3 in d2)
        {
            if (d3.Name.IndexOf(".svn") == -1)
            {
                DeleteSvn(d3.FullName);
            }
            else
            {
                FileCtrl.DirectoryDelete(d3.FullName);
            }
        }
    }

    private void geshihuariqi3()
    {
        StringBuilder tempStr = new StringBuilder();
        var tb1 = this.tabControlCenter.SelectedTab;
        if (tb1 != null && tb1.Controls.Count > 0)
        {
            if (tb1.Controls[0].Tag == null)
            {
                var control = (tb1.Controls[0] as MyRichTextBox);
                if (!string.IsNullOrEmpty(control.Text))
                {
                    //var lines = control.SelectedText.Split(new string[] { "\n" }, StringSplitOptions.None);
                    var lines = control.Text.Split(new string[] { "\n" }, StringSplitOptions.None);
                    foreach (var s in lines)
                    {
                        //                string result = Regex.Replace(s, @"((\d{4}|\d{2})(\-|\/|\.)\d{1,2}\3\d{1,2})",
                        //new MatchEvaluator(CapText));

                        //11.11变成2050年11月11日 然后在手动替换
                        var s1 = s.Trim();
                        DateTime result;
                        if (DateTime.TryParse(s1.ToString(), out result))
                        {
                            var strTime = result.ToString("yyyy年M月d日");
                            tempStr.AppendLine(strTime);
                        }
                        //Regex r = new Regex(@"^\d+(\.)\d+$");
                        //Match m = r.Match(s1);
                        //if (m.Success)
                        //{
                        //    string s2 = m.Value.ToString();
                        //    string[] ss1 = s2.Split('.');
                        //    string sy = ss1[0];
                        //    string sr = ss1[1];

                        //    //Console.WriteLine(s);
                        //    //m = m.NextMatch();

                        //    tempStr.AppendLine("2050年" + sy + "月" + sr + "日");
                        //}
                        else
                        {
                            tempStr.AppendLine(s);
                        }
                    }

                    //control.SelectedText.Replace(control.SelectedText,tempStr.ToString());
                    control.Text = tempStr.ToString();
                }
            }
        }
    }

    private void geshihuariqi2()
    {
        StringBuilder tempStr = new StringBuilder();
        var tb1 = this.tabControlCenter.SelectedTab;
        if (tb1 != null && tb1.Controls.Count > 0)
        {
            if (tb1.Controls[0].Tag == null)
            {
                var control = (tb1.Controls[0] as MyRichTextBox);
                if (!string.IsNullOrEmpty(control.Text))
                {
                    //var lines = control.SelectedText.Split(new string[] { "\n" }, StringSplitOptions.None);
                    var lines = control.Text.Split(new string[] { "\n" }, StringSplitOptions.None);
                    foreach (var s in lines)
                    {
                        //                string result = Regex.Replace(s, @"((\d{4}|\d{2})(\-|\/|\.)\d{1,2}\3\d{1,2})",
                        //new MatchEvaluator(CapText));

                        //11.11变成2050年11月11日 然后在手动替换
                        var s1 = s.Trim();
                        Regex r = new Regex(@"^\d+(\.)\d+$");
                        Match m = r.Match(s1);
                        if (m.Success)
                        {
                            string s2 = m.Value.ToString();
                            string[] ss1 = s2.Split('.');
                            string sy = ss1[0];
                            string sr = ss1[1];

                            //Console.WriteLine(s);
                            //m = m.NextMatch();

                            tempStr.AppendLine("2050年" + sy + "月" + sr + "日");
                        }
                        else
                        {
                            tempStr.AppendLine(s);
                        }
                    }

                    //control.SelectedText.Replace(control.SelectedText,tempStr.ToString());
                    control.Text = tempStr.ToString();
                }
            }
        }
    }

    private void textBox1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            dofunction();
        }
    }

    private async Task AddTabAndOpenWebPageAsync(string name, string url)
    {
        // 创建一个新的 TabPage
        TabPage newTabPage = new TabPage(name);

        // 创建一个新的 CefSharp 控件
        //ChromiumWebBrowser browser = new ChromiumWebBrowser(url)
        //{
        //    Dock = DockStyle.Fill
        //};
        WebView2 browser = new WebView2
        {
            Dock = DockStyle.Fill
        };
        await browser.EnsureCoreWebView2Async(null);

        // 加载 Edge 插件
        var userDataFolder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft", "Edge", "User Data");
        browser.CoreWebView2.Settings.IsGeneralAutofillEnabled = true;
        browser.CoreWebView2.Navigate(url);
        //WebView browser = new WebView
        //{
        //    Dock = DockStyle.Fill,
        //    Url = url
        //};
        //browser.Source = new Uri(url);
        // 将 CefSharp 控件添加到 TabPage
        newTabPage.Controls.Add(browser);

        // 将 TabPage 添加到 TabControl
        tabControlCenter.TabPages.Add(newTabPage);

        // 选择新添加的 TabPage
        tabControlCenter.SelectedTab = newTabPage;
    }

    public class ButtonConfig
    {
        public string Name { get; set; }
        public string Url { get; set; }
    }

    //private void InitializeFlowLayoutPanel()
    //{
    //    flowLayoutPanel = new FlowLayoutPanel
    //    {
    //        Dock = DockStyle.Right,
    //        FlowDirection = FlowDirection.LeftToRight,
    //        AutoSize = true,
    //        Height = panel_top.Height,
    //        WrapContents = true
    //    };
    //    panel_top.Controls.Add(flowLayoutPanel);
    //}

    private void LoadButtonConfigs()
    {
        //var settings = new CefSettings();
        //settings.CefCommandLineArgs.Add("enable-media-stream", "1"); // 启用媒体流（HTML5 支持）
        //Cef.Initialize(settings);

        string configFilePath = "xml/buttonConfig.json";
        if (File.Exists(configFilePath))
        {
            string json = File.ReadAllText(configFilePath);
            List<ButtonConfig> buttonConfigs = JsonConvert.DeserializeObject<List<ButtonConfig>>(json);

            foreach (var config in buttonConfigs)
            {
                CreateButton(config.Name, config.Url);
            }
        }
    }

    //private FlowLayoutPanel flowLayoutPanel;
    private void CreateButton(string name, string url)
    {
        Button button = new Button
        {
            Text = name,
            Tag = url,
            AutoSize = true
        };
        button.Click += (sender, e) => Button_Click(sender, e, name, url);
        // 将按钮添加到你的表单或容器中
        this.flowLayoutPanel.Controls.Add(button);
    }

    private void Button_Click(object sender, EventArgs e, string name, string url)
    {
        AddTabAndOpenWebPageAsync(name, url);
    }
}